I'm having problem with this code.
Here's what I'm trying to do.
I want the user to enter the firstname, last name of the person whom he wants to delete from the phonebook.
then I try to compare the data entered by user with the names already stored on phonebook.
if the name doesnot match, it stores that name on the phonebook again.
If it matches then it won't store it on phonebook again.
So this way the contact which user wanted to delete will not be stored again on the file and ultimately which means it got deleted.
Here is my code but I'm not able to do what i wanted to.
Please if you can help me figure out where the problem is?
void delete(string contacts[], string fName, string lName, ifstream& aInFile, ofstream& aOutFile) {
cout << "DELETE A CONTACT\n";
cout << "Type the contacts first name\n";
cin >> fName;
cout << "Type the contacts last name\n";
cin >> lName;
int j = 0;
while(!aInFile.eof()){
aInFile.open(OUTPUT_FILE);
checkFileOpen(aInFile);
aInFile >> contacts[j];
string x = contacts[j];
aInFile >> contacts[j];
string y = contacts[j];
aInFile >> contacts[j];
string z = contacts[j];
aInFile.close();
if (lName != x || fName != y){
cout << "couldn't find contact with Name" << fName << lName << endl;
aOutFile.open(OUTPUT_FILE, ios::app);
checkFileOpen(aOutFile);
aOutFile << x <<"\t" << y <<"\t" << z <<endl;
aOutFile.close();
}else if ( fName == y && lName == x){
cout << "deleted"<< endl;
}
j++;
}
}
Thanks.