arnuld said:
ok. i use Linux, EOF character is an integer "-1".
The C standard does not specify the value of the macro EOF, just that
it expands to a value of type int that is the implementation's choice
for specifying end-of-file conditions. It's commonly -1, but that's
not a strictly portable assumption.
if i enter "-1"
output is still "1"
but if i type "Ctrl-D" then output is "0" (zero).
All input is treated as a sequence of characters. The character
sequence "-1" expands to the value specified in the system's character
set for '-' followed by that for '1'. Otherwise you will not be able
to enter "-1" when you want to do so. Signalling end-of-file, among
others is a control sequence. It's not meant to interfere with the
values assigned for normal input, hence special key sequences are
assigned to generate such values. Under UNIX systems it's commonly
generated by the key sequence 'Ctrl-d', (hold down the Control key and
press 'd'). Under Windows it's 'Ctrl-z'
BTW, if EOF is defined as an integer inside <stdio.h>, then why do i
get "1" when i give "-1" as input ?
That's because to specify it from the keyboard, special key sequences
are needed to prevent it from interfering with normal input values.
Similarly, the system's end-of-line can be generated by Ctrl-m under
Unices.