void Contact::updatecontact()
{
Contact C;
fstream file;
file.open("Contacts", ios::in | ios::out | ios::binary);
long pos;
int option;
char nname[30],nemail[50];
long ntelno,nmobno;
gotoxy(0,8);
cout << "How would you like to search for the contact \n";
cout << " 1. Name \n 2. Email \n 3. Residence No. \n 4. Mobile No. \n 5. Exit \n";
cin >> option;
switch(option)
{
case 1:
{
cout << "Enter the name of the contact \n";
cin>>nname;
while(file.read((char*)&C,sizeof(C)))
{
if(strcmpi(C.retname(),nname)==0)
{
pos = file.tellg();
C.Modify();
file.seekp(pos-sizeof(C));
file.write((char*)&C,sizeof(C));
}
}
break;
}
So, here's part of my program. At the moment the problem I'm experiencing is that if I choose the contact that is stored LAST (ONLY THE LAST ONE) and update its details, the program, instead of overwriting it, puts the modified data as a separate block BEFORE the last contact. For example,
I have the contacts
Abc
Def
Ghi
I can edit Abc and Def just fine... but if I choose Ghi, and say replace the details with Name as Xyz, this is what I get