hi guys
i am having a problem with the following bit of code - i am quite new to programming. It is supposed to read a file line by line and compare the resultant string against another string that has been imputed by the user. (the end of file bit has been taken out cos it seems to screw it up even futher)
Code:
//while (! vehicles.eof() )
//{
do
{
vehicles.getline(buffer,9);
if (!strcmp(buffer,index)) cout << "Vehicle on hire\n";
else cout << "Vehicle not on hire\n";
}
while (strcmp (buffer,index) !=0);
//if (!strcmp(buffer,index)) cout << "Vehicle on hire\n";
//else cout << "Vehicle not on hire\n";
//vehicles.seekg(pos);
//}
basically if i leave string comparison and output in the do section it will return "Vehicle not on hire" for every string bar the one that matches (where it outputs "Vehicle on hire") but will just output "Vehicle not on hire" in a continuous loop if no strings match. if however, i leave the code in the while section it will output "Vehicle on hire" for a matching (string which is better) but will just lock up if you input a string that is not on the text file. this seems to happen no matter what i put in the while section and if i try it using an if else statement.
any ideas what i am doing wrong?
thanks in advance