Created
December 10, 2011 02:42
-
-
Save k4rtik/1454373 to your computer and use it in GitHub Desktop.
generates email IDs and stores them in a file - first year programming assignment - September 23, 2009
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// file: string-func.cpp | |
// generates email IDs and stores them in a file | |
// author: Kartik Singhal | |
#include <iostream> | |
#include <cstring> | |
#include <fstream> | |
using namespace std; | |
int main() | |
{ | |
char atDomain[] = {"@nitc.ac.in"}; | |
char name[30], enrolID[10], | |
emailID[strlen(atDomain) + 40]; | |
char temp1String[40], temp2String[40]; | |
bool flag=true; | |
fstream mailfile("emails.txt", ios::app); | |
mailfile.close(); | |
cout<<"Please enter the following details:\n"; | |
cout<<"Name: "; | |
cin.getline(name, 30); | |
cout<<"Enrolment ID: "; | |
cin.getline(enrolID, 10); | |
//converting enrolID to required format | |
enrolID[7]='\0'; | |
if(isupper(enrolID[0])) | |
enrolID[0]+=32; | |
strcpy(temp1String, name); | |
//converting name to a form suitable for email ID | |
for(int i=0; i<strlen(temp1String); i++) | |
{ | |
if(isupper(temp1String[i])) | |
temp1String[i]+=32; | |
if(temp1String[i]==' ' || temp1String[i]=='.') | |
for(int j=i--; j<strlen(temp1String); j++) | |
temp1String[j]=temp1String[j+1]; | |
} | |
strcpy(emailID, temp1String); | |
strcat(emailID, atDomain); | |
cout<<"\nThe generated email ID is: "<<emailID<<endl; | |
cout<<"\nPlease wait, checking whether this ID already exists...\n"; | |
mailfile.open("emails.txt", ios::in); | |
while(!mailfile.eof()) | |
{ | |
cout<<"check"; | |
mailfile>>temp2String; | |
if(!strcmp(temp2String, emailID)) | |
{ | |
cout<<"Done!\nThis ID already exists!"<<endl; | |
flag=false; | |
break; | |
} | |
} | |
mailfile.close(); | |
mailfile.open("emails.txt", ios::app|ios::out); | |
if(flag) | |
{ | |
cout<<"Done!\nThis ID doesn't exist in the database!"<<endl; | |
mailfile.seekp(0, ios::end); | |
mailfile<<emailID<<endl; | |
} | |
else | |
{ | |
cout<<"\nGenerating new ID..."<<endl; | |
strcat(temp1String, enrolID); | |
strcpy(emailID, temp1String); | |
strcat(emailID, atDomain); | |
cout<<"The newly generated ID is: "<<emailID<<endl; | |
mailfile.seekp(0, ios::end); | |
mailfile<<emailID<<endl; | |
} | |
cout<<"\nemail ID saved."<<endl; | |
mailfile.close(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment