Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!umcp-cs!chris From: chris@umcp-cs.UUCP (Chris Torek) Newsgroups: net.lang.c Subject: Re: How it got "broke"... Message-ID: <3966@umcp-cs.UUCP> Date: Wed, 22-Oct-86 00:07:39 EDT Article-I.D.: umcp-cs.3966 Posted: Wed Oct 22 00:07:39 1986 Date-Received: Wed, 22-Oct-86 22:14:28 EDT References: <1322@umd5> Reply-To: chris@umcp-cs.UUCP (Chris Torek) Organization: University of Maryland, Dept. of Computer Sci. Lines: 22 In article <1322@umd5> don@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@umcp-cs ARPA: chris@mimsy.umd.edu