getc() != EOF

ken at turtlevax.UUCP ken at turtlevax.UUCP
Tue May 29 16:30:42 AEST 1984


Beware that an alternative test for end-of-file doesn't seem to work on
4.2bsd like it did on 4.1 and before.  I am referring to feof():

	while (!feof(stdin)) putchar(getchar());

does not work.  It seems that the EOF indicator does not come on until
the EOF marker has been read. Previous versions of the standard I/O
library set the EOF flag if the last character has been read and the
next one will be and EOF.  TO run correctly on 4.2, one needs to do:

	while ((i = getchar()) != EOF) putchar(i);

or

	for (i = getchar(); !feof(stdin); i = getchar()) putchar(i);

-- 
Ken Turkowski @ CADLINC, Palo Alto, CA
UUCP: {amd70,decwrl,flairvax}!turtlevax!ken



More information about the Comp.unix.wizards mailing list