Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!sundc!hadron!jsdy From: jsdy@hadron.UUCP (Joseph S. D. Yao) Newsgroups: comp.lang.c Subject: Re: Question about feof() Message-ID: <346@hadron.UUCP> Date: Tue, 30-Dec-86 07:00:36 EST Article-I.D.: hadron.346 Posted: Tue Dec 30 07:00:36 1986 Date-Received: Tue, 30-Dec-86 21:47:05 EST References: <31800001@garrity> Reply-To: jsdy@hadron.UUCP (Joseph S. D. Yao) Organization: Hadron, Inc., Fairfax, VA Lines: 24 Summary: fwrite() never reaches EOF (mas o menos) In article <31800001@garrity> garrity@garrity.applicon.UUCP writes: > The following routine ... prints a 0, followed by a 1. > #include> main() > { FILE *f; char string[16]; > f = fopen("/dev/null","r"); > printf("%d\n",fread(string,16,1,f)); > printf("%d\n",feof(f)); > } > If I change the "r" to a "w", ... feof() now returns a 0. Well, the fread() on a FILE opened for writing should return an error, and in fact returns(0). The feof() tests for the EOF bit in the flags, which is never set in this circumstance -- since you can write to /dev/null (or, theoretically, any other file) and never reach bottom. /* STAMP OUT FASCIST PROGRAMS */ /* THAT ENFORCE MINIMUM AMOUNT */ /* OF RETURN MATERIAL! */ -- Joe Yao hadron!jsdy@seismo.{CSS.GOV,ARPA,UUCP} jsdy@hadron.COM (not yet domainised)