NOT overwriting

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
	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

Abc
Def
Xyz
Ghi

Instead of

Abc
Def
Xyz

Can someone please explain?
Last edited on
Topic archived. No new replies allowed.