Hi,
I have to create a structure for student record and save their data, but I am having trouble in storing that data.
This is what I have:
struct student
{
char id[7];
char firstname[20], lastname[20];
char phoneno[15];
char address[100];
dobtype dateofbirth;
};
int main(int argc, char *argv[])
{
int choice;
student stdrec[200];
int i=0;
cout<<"************** Address Book Menu *********** "<<entries<<" ****"<<endl;
cout<<"1. Add an Entry"<<endl;
cout<<"2. Display all Entries"<<endl;
cout<<"3. Search an Entry"<<endl;
cout<<"4. Delete an Entry"<<endl;
cout<<"5. Exit\n>>"<<endl;
cin>>choice;
switch(choice)
{
case 1:
cout<<"Enter ID: ";
cin>>stdrec[i].id;
cin.ignore(200,'\n');
cout<<"Enter Firstname: ";
cin.getline(stdrec[i].firstname,20);
cin.ignore(200,'\n');
cout<<"Enter Lastname: ";
cin.getline(stdrec[i].lastname,20);
cin.ignore(200,'\n');
cout<<"Enter phoneno: ";
cin.getline(stdrec[i].phoneno,15);
cin.ignore(200,'\n');
cout<<"Enter address: ";
cin.getline(stdrec[i].address,100);
cin.ignore(200,'\n');
cout<<"Enter Date of Birth: ";
cout<<"Month: ";
cin>>stdrec[i].dateofbirth.month;
cout<<"Day: ";
cin>>stdrec[i].dateofbirth.day;
cout<<"Year: ";
cin>>stdrec[i].dateofbirth.year;
break;
case 2:
break;
}
}
The problem is when I enter 7 digits for Id it works, but when I enter 20 character for firstname, it then just displays the rest cout statements and the program terminates.
I tried to debug it and what I found was when I input firstname, first 9 characters are concatenated with the Id and other 9 characters are saved in firstname, after that I doesnt let the user enter anything...