Searching for an entry in a file?
I have a problem regarding the code for searching a text file. My program is able to add information, display, and save it to a text file, but I'm having trouble figuring out how to search the text file for a particular entry.
The entries in my text file look like this:
0843543 Intro to C++ HH117
I'm trying to implement a function to search the text file by the first value (ie: 0843543). I tried using a strcmp but it would not find the match.
The code for this was:
Code:
void SearchClass()
{
char input[7];
char course[7];
int i;
cout<<"enter in course to search: ";
cin>>course;
fstream readfile;
readfile.open("C:/WINDOWS/Desktop/class.txt", ios::in);
readfile.getline(input, 7);
while(!readfile.eof())
{
if(strcmp(course, input)==0)
{cout<<"match";}
else
{cout<<"no match";}
readfile.getline(input, 7);
}
readfile.close();
}
Once it finds the match I need to be able to delete it or change it. Thanks again for all the help.