2 ms·
It's very bad. Using feof() to somehow ask if a stream has reached EOF before doing any I/O is wrong. Code like this comes up very often on Stack Overflow so i
by unwind 12y ago
It's very bad.
Using feof() to somehow ask if a stream has reached EOF before doing any I/O is wrong. Code like this comes up very often on Stack Overflow so it seems it's somehow intuitive for people, or suggested by some tutorials or something.
The purpose of feof() is to answer, after I/O has failed, if it failed due to the stream reaching EOF.
It's also utterly pointless in this code, it should just check the return value of fscanf() and stop when it fails to convert the desired number of values. This, on the other hand, seems deeply surprising to most people, you very rarely see code that cares about the return value when scanning. Which is strange; I/O can fail.
Further, since fscanf() basically ignores embedded whitespace, I'm not at all sure it will do as expected and read six floats per physical line of input.
Lastly, yes of course it's strange to use the super-flexible fscanf() if you're looking for performance.