|
Presume that this is the last thing in your file: abcdefg\n(EOF). The input mechanism is satisfied when it reads the \n. It is sitting between that and the EOF. You use that, then return to the top of the while, which is NOT showing EOF. You read and immediately hit EOF. Since you aren't looking to see if that's the case, you read for a name, some chars, and some scores, each of which does absolutely nothing, since the stream failed on the try for a name and has been blithely ignoring you. Didn't keep you from trying to use the stuff you already had, though. Look at each individual read mechanism you use. Ask what happens if it hits EOF before getting anything. If you don't, you'll reuse crap. Ask, also, what happens if it hits EOF AFTER getting some stuff. If you don't recognize THAT, you'll throw good stuff away. It is a common newbie mistake to rely on EOF or FAIL in the while expression, only. Sometimes that's workable, mostly not.
|