Hey, thank you guys for your inputs. I've been stuck on this problem for a week now so any help is welcome :)
futanari, have you made sure to prime the pump first before using eof() (i.e. attempt to read in the first item)? Attempting to do so will set the eof flag which then lets the program know when the end of file is by looking for the set flag. The .eof() function doesn't exactly work the way we think it should lol.
Thomas, thanks for the page reference. Unfortunately, we are not allowed to use the string library nor have we had experience yet with the <sstream> library.
Oh and just to clarify what my question really was, I was curious as to how the ifstream worked when I need to compare arrays of characters. For example, I want to read in an animal's breed from the file and then compare that to the breed the user is searching for.
Question is, do I have to create local variables to store the read in information?
For example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
char temp_name[SIZE] //SIZE is a constant int of 40
char breed_match[SIZE] //asks user what breed they're looking for
//Reading in the animal's name first
file_in.get(temp_name,SIZE,':'); //colon delimiter because that's what I used as a delimiter
file_in.ignore(100,':');
//From this point, I'm assuming that the word "Dog" is now stored in my
//char temp after it was read in from my text file. I then proceed
//by creating other local variables to store the rest of the animal's information.
//After all of this is said and done, I now want to compare breed_match with temp_breed
if(strcmp(breed_match, temp_breed) == 0)
return true;
return false;
|
So this is just an example. Is this correct thus far? Or does it not work the way I think it does? Thanks!