Mark McIntyre said:
Lets be completely rigorous, so as to avoid any further confusion
between EOF and EOF
Yes, let's be completely rigorous.
EOF is macro returned by some library functions when an EOF condition
is signalled by the IO library. The EOF macro is in integer constant
with type int and a negative value. The EOF signal is something that
you need to generate if you want the OP's original proggy to work.
Neither of the above is necessarily the same as the EOF character
found in some ASCII charsets.
EOF is a macro defined in <stdio.h>. It "expands to an integer
constant expression, with type int and a negative value, that is
returned by several functions to indicate _end-of-file_, that is, no
more input from a stream". Note that it's an integer constant
*expression*; an integer constant cannot have a negative value.
There is no "EOF signal". There is an end-of-file *indicator*
associated with an input stream. The word "signal" means something
else; see C99 7.14, "Signal handling", for details. I understand that
you were using the term "signal" in its common English sense, but it's
important to be precise.
<OT>
There is no character in ASCII named "EOF". Perhaps you're thinking
of "EOT"? Or was there an "EOF" character in some obsolete version of
ASCII?
</OT>
If you're running a program that takes input from an interactive
device (say, a keyboard), you need to know how to cause the
end-of-file indicator for an input stream associated with that device
to be set. That, I believe, is the probelm the OP was having (Mark,
you were right about that). The C standard says nothing about how
this is done, but typically typing either control-D or control-Z,
depending on the system, will do the job. This causes the end-of-file
indicator to be set, which causes the next call to getchar() (or
fgetc(), or ...) to return the value of EOF. (It also causes a call
to feof() to return true, but that's not as useful as some programmers
think it is.)