V
Vladimir S. Oka
Ben said:I know you can have empty data! I meant the program exhibited UB when
presented with an empty file because of what is does *after* testing
for
eof. The test if fine, but it won't return true so scanf is called
with no data to read -- that was what I was trying to say with "...
because
there may be no data to read". I should have been more explicit about
the UB comming from the read, not the eof test.
I don't think so. The fscanf is in the "else". It was the main point
I wanted to correct.
Sorry, I failed to notice a trailing `{` in the `else` part, and didn't
count the bottom ones. I saw just a `;` after `printf` and mentally
terminated the `else`. Comes from being used to a different coding
style that mandates curly braces on their own lines.
I thought that feof would not return true unless an input operation
had
failed. I may not be up on the latest standard so I will await
correction here, but if I am not mistaken your suggestion involved
reading when there might be nothing to read (and hence demons etc...).
As a I looked it up in the Standard, the `feof` does not require any
data to be read before testing for EOF condition. Looking elsethread, I
see that I have failed to test success of `fscanf`, and relied only on
`feof` for looping, but that's a different issue, I think.
--
BR, Vladimir
Hatred, n.:
A sentiment appropriate to the occasion of another's
superiority.
-- Ambrose Bierce, "The Devil's Dictionary"