Michael C. Toren on Fri, 18 Jan 2002 14:03:24 -0500


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: [PLUG] EOF


paul@dpagin.net wrote:
> > I'm using Linux to program C, however, when I try to do something like (
> > c = getchar() ) != EOF

Do you have 'c' defined as a char, or as an int?  getchar() returns an
int rather than a char, using the high bits to indicate error conditions
such as EOF, and the lower bits to hold the value of valid data returned.

gr@eclipsed.net wrote:
> Have you tried using '^V^D' there instead of literally typing out
> EOF? (That's control-V control-D. ^V makes the subsequent control
> character visible.)

In this context, EOF is a conditioned returned by read(), not a character.
(It's perfectly valid to read ASCII character 4, ^D, from a file).

> EOF is #defined in a system include somewhere which you're probably
> not including in your source. Figuring out which include file would

EOF is defined in stdio.h, along with getchar() and friends.  (If it
wasn't defined, cc wouldn't be compiling the code in the first place)

-mct