What's so bad about scanf anyway??? (really what's bad about gets)

Michael Salmon epames at eos.ericsson.se
Tue Nov 20 23:30:36 AEST 1990


In article <4319 at goanna.cs.rmit.oz.au> Richard A. O'Keefe writes:
>gets() will keep on reading from stdin until it hits a \n or an EOF.
>Lines entered from a keyboard _normally_ end with a \n, but they don't
>have to.  Let <EOF> represent your end-of-file character on a UNIX system

This is getting a long way from the original point but I thought I
should respond to this statement. In C EOF is not a character, its
value is such that it can *NEVER* be present in a file. In all the C
implementations that I have ever seen EOF has been represented by the
value -1 but it can be any integer and one of the traps that I think
everyone falls for at some time is to presume that getc() returns a
character rather than an integer.  EOF is never 255 or ^D, it is in
fact a read() that returns 0 as the byte count. N.B. the least
significant char of the usual representation of -1 is 255.

Michael Salmon
L.M.Ericsson
Stockholm



More information about the Comp.lang.c mailing list