The getchar()
function returns either the numeric value of the character that was just entered (treated as an unsigned char
, so it's never negative), or the special value EOF
which indicates that there is no more input.
Windows uses Control-Z to trigger and end-of-file condition, which causes getchar()
to return the value EOF
. But EOF
is not a character value; it's specifically chosen to be a value that cannot be a character value.
End-of-file is a condition, not a value. EOF
is a numeric value, but not a character value; it's the value returned by getchar()
to indicate that input is in an end-of-file condition (or an error condition).
(If you want to read integer values, positive or negative, you need to read a single character at a time and then compute the integer value that the character sequence represents. The integer value -1
can be entered as the character '-'
followed by the character '1'
. C has various functions, like atoi
and the *scanf
family, that can do that conversion.)