Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!umich!samsung!zaphod.mps.ohio-state.edu!sdd.hp.com!ucsd!ucbvax!BRL.MIL!moss From: moss@BRL.MIL ("Gary S. Moss", VLD/VMB) Newsgroups: comp.sys.sgi Subject: Re: uncanny casting coercion Message-ID: <9005311338.aa03378@VMB.BRL.MIL> Date: 31 May 90 17:38:40 GMT Sender: daemon@ucbvax.BERKELEY.EDU Organization: The Internet Lines: 36 < Observation 1) < .............. < char *fgets(s,n,stream); et al return EOF on end of file No they don't, they return NULL. < and a NULL pointer in s. Wrong again. This is not even possible; s should point to storage, this cannot be changed by fgets. Characters can be transferred to the storage location whose address is contained in s, but that address (the value of s) cannot be changed by fgets. If this is confusing, get some C pointer training before you do any further programming. < The compiler will not allow a test < < if(EOF==fgets(s,n,stream)) { ... Well, at least it gets this right. ;-b < I had to do < < if((char *)EOF==fgets(s,n,stream)) { ... Will you forget EOF already. EOF is not a pointer value and has no meaning in that context. < DIAGNOSTICS < If end-of-file is encountered and no characters have been read, no ^^ < characters are transferred to s and a NULL pointer is returned. If a ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^ < read error occurs, such as trying to use these functions on a file that < has not been opened for reading, a NULL pointer is returned. Otherwise ^^^^^^^^^^^^^^^^^^^^^^^^^^ < s is returned. You better RTFM *again*. ;-) Good luck!