looping problem

This is a discussion on looping problem within the C++ Programming forums, part of the General Programming Boards category; ok i think i have a problem with my loop in a function. i am reading a file to it ...

looping problem

ok i think i have a problem with my loop in a function. i am reading a file to it and i need it to check to see if the buffer is equal to the user input, and if not go to the next line and do the sane again and print out when the result is found

i think the problem is in the loop as its not working properly but not sure, can someone please help

REmember, array indexes are 0 based. That means that temp will only hold 4 readable char and a null char given declaration of:

char temp[5];

Therefore trying to compare buffer[5] with temp[5] as in :

if (buffer[5] == temp[5])

won't work because temp[5] is garbage, doesn't exist, etc.

If the flight number is 5 digits/letters long, then temp should be declared with 6 elements so temp[5] will be the sixth char in the string, and will actually be the null char, with temp[0] through temp[4] being the readable char of the flight number. I would not try to compare temp[5] with buffer[5] either, because unless buffer.size() == 5, meaning getline() put a null char at buffer[5], then buffer[5] will never have a chance to equal temp[5], even then. I'd just compare temp[0] through temp[4] with buffer[0] through buffer[4] if flight number is 5 char long.