Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Path: utzoo!mnetor!seismo!cmcl2!husc6!panda!genrad!decvax!linus!raybed2!applicon!bambi!garrity!garrity
From: garrity@garrity.applicon.UUCP
Newsgroups: comp.lang.c
Subject: Question about feof()
Message-ID: <31800001@garrity>
Date: Thu, 18-Dec-86 13:34:00 EST
Article-I.D.: garrity.31800001
Posted: Thu Dec 18 13:34:00 1986
Date-Received: Sat, 20-Dec-86 21:40:25 EST
Lines: 39
Nf-ID: #N:garrity:31800001:000:1115
Nf-From: garrity.applicon.UUCP!garrity    Dec 18 13:34:00 1986


   Could someone out there in net-land explain the reason for the 
following behaviour?

   The following routine does exactly what I would expect, that is,
it 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", then I get a surprise.  The call to
feof() now returns a 0.  Why is that?  I was also a little surprised
to discover that leaving the call to fread() out will also cause feof()
to return 0, but that sort of makes sense.  

BTW, I am running on a Sun with V3.0 of Sun's OS.  
				(i.e. Bsd 4.2 and change :-))

--                                                          -MPG-
-- Mike Garrity
--
-- Things fall apart.  It's scientific.
--
-- snail: Applicon, a division of Schlumberger Systems, Inc.
--        829 Middlesex Tpk.
--        P.O. box 7004
--        Billerica MA, 01821
--
-- uucp: {allegra|decvax|mit-eddie|utzoo}!linus!raybed2!applicon!garrity
--       {amd|bbncca|cbosgd|wjh12|ihnp4|yale}!ima!applicon!garrity