Question about feof()

garrity at garrity.applicon.UUCP garrity at garrity.applicon.UUCP
Fri Dec 19 04:34:00 AEST 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 <stdio.h>
	
	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



More information about the Comp.lang.c mailing list