uncanny casting coercion

"Gary S. Moss", VLD/VMB moss at BRL.MIL
Fri Jun 1 03:38:40 AEST 1990


< 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!



More information about the Comp.sys.sgi mailing list