How it got "broke"...
Chris Torek
chris at umcp-cs.UUCP
Wed Oct 22 14:07:39 AEST 1986
In article <1322 at umd5> don at umd5 (Chris Sylvain) writes:
>Why "while( fputc(fgetc(fd), fe) != EOF )" quit working as it
>did under both 2.9BSD and Ultrix 1.2 ...
Chances are it never really worked: fputc(EOF, fe) is likely to
put a meta-DEL into file `fe'.
>1) At the end of file, fgetc() returns (int) -1.
>2) fputc() prints (char) -1 and then returns a CHAR not an INT.
Actually, fputc returns (unsigned char)c, which turned EOF to 255.
>Naturally, (int) -1 != (char) -1, so we have a problem.
On Ultrix 1.2 Vaxen and 2.9BSD 11s, (int) -1 *is* equal to
(char) -1. The code is wrong in the first place; fputc is
not supposed to be handed an EOF. What it does in such cases
is undefined.
--
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7690)
UUCP: seismo!umcp-cs!chris
CSNet: chris at umcp-cs ARPA: chris at mimsy.umd.edu
More information about the Comp.lang.c
mailing list