Page 441 - C++
P. 441
{
Contact C;
char name1[20],r;
int flag=0;
ifstream fin("contact.dat",ios::in|ios::binary);
ofstream fout("cont_temp.dat",ios::out|ios::binary);
cout<<"\nEnter name to be deleted ";
gets(name1);
while(fin.read((char*)&C,sizeof(C)))
{
if(strcmpi(name1,C.Return_Name())==0)
{
flag=1;
cout<<"This is the record you want to delete: ";
C.CDisplaydata();
cout<<"\nAre you sure?? ";
cin>>r;
if(r=='y'||r=='Y')
{
cout<<"Your record is deleted :) ";
}
else
{
fout.write((char*)&C,sizeof(C));
}
}
else
{
fout.write((char*)&C,sizeof(C));
}
}
if(flag==0)
{
cout<<"\nNo record found";
}
fin.close();
fout.close();
remove("contact.dat");
rename("cont_temp.dat","contact.dat");
}
/*************************************************************/
void modify_contact()
{
ifstream fin("contact.dat",ios::in|ios::binary);
ofstream fout("temp.dat",ios::out|ios::binary);
Contact C;
char name1[20];
int flag=0;
cout<<"\nEnter the name whose record is to be modified: ";
gets(name1);
while(fin.read((char*)&C,sizeof(C)))
{