Is EOF always negative?
I’m thinking of writing a function that reads the next word in the input and returns the line number the word was found in or EOF if the end of the input has been reached. If EOF is not necessarily negative, the function would be incorrect.
Yes, EOF is always negative.
The Standard says:
Note that there’s no problem with “plain”
charbeing signed. The<stdio.h>functions which deal withchars, specifically cast the characters tounsigned charand then toint, so that all valid characters have a positive value. For example: