if (choice == 1)
{//open if 1
clrscr();
cout << "Please enter your friend's name : ";
cin.ignore();
cin.getline(name,30);
cout << endl;
cout << "Please enter friend's IC number : ";
cin >> IC;
cout << endl;
cout << "Please enter your friend's address : ";
cin.ignore();
cin.getline(address,60);
cout << endl;
cout << "Please enter your friend's home phone number : ";
cin >> hpnum;
cout << endl;
cout << "Please enter your friend's office phone number : ";
cin >>opnum;
cout << endl;
cout << "Please enter your friend's mobile phone number : ";
cin >> mpnum;
break; //terminate loop if ic is matching with request
} //close if while 1
if(infile.eof() && IC != requestIC)
{//open if while 2
cout << "No such IC " << endl;
} //close if while 2
} //close while
infile.close();
cout << "Please press enter to continues... " << endl;
getch();
} //close if 2
}while (choice!=4);
if (choice == 4)
{
exit(1);
}
getch();
return 0;
}
This is an application could display a person's information from a text file ,when you key in the identification card number.I had done the part of of record the information and retrieve the information,but wonder how to do the part of the delete information .How to write the "delete" function actually ?I had refer some of the tutorial ,they mentioned something about like"->" or even call WINDOWS system delete function to get rid of the data in the text file.
To write delete function follow this algo-
open file
ask user to which record he wants to remove
make an output file
make a loop that will go from first record to last.
write all the records in the output file except the record which user has entered
delete your data file
rename output file as your data file name.
}
}
infile.close();
outfile.close();
cout << "Please press enter to continues... " << endl;
getch();
}
This is a part of the lines of code as the delete fucntion according to the algorithm of aakashjohari.It still incomplete because of the final two lines of algorithm i don't know how to write.....
delete your data file
rename output file as your data file name.
if (choice == 1)
{//open if 1
clrscr();
cout << "Please enter your friend's name : ";
cin.ignore();
cin.getline(name,30);
cout << endl;
cout << "Please enter friend's IC number : ";
cin >> IC;
cout << endl;
cout << "Please enter your friend's address : ";
cin.ignore();
cin.getline(address,60);
cout << endl;
cout << "Please enter your friend's home phone number : ";
cin >> hpnum;
cout << endl;
cout << "Please enter your friend's office phone number : ";
cin >>opnum;
cout << endl;
cout << "Please enter your friend's mobile phone number : ";
cin >> mpnum;
cout << "Please press enter to continues... " << endl;
getch();
}
Finally , i had successfuly write the last two part of the algorithm.What i want is to make a function for the remove() in case i want to use it later for further coding.But the error of type name expected occured.How to solve it ?By the way i'm using the Borland C++ compiler,is there any problems messing with it ?