Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!snorkelwacker.mit.edu!bloom-beacon!eru!hagbard!sunic!mcsun!ukc!edcastle!aiai!richard From: richard@aiai.ed.ac.uk (Richard Tobin) Newsgroups: comp.lang.c Subject: Re: What's so bad about scanf anyway??? (really what's bad about gets) Message-ID: <3797@skye.ed.ac.uk> Date: 21 Nov 90 15:46:01 GMT References: <1990Nov16.165203.18786@zoo.toronto.edu> <4319@goanna.cs.rmit.oz.au> <1990Nov20.123036.11103@ericsson.se> Reply-To: richard@aiai.UUCP (Richard Tobin) Organization: AIAI, University of Edinburgh, Scotland Lines: 35 In article <1990Nov20.123036.11103@ericsson.se> epames@eos.ericsson.se writes: >should respond to this statement. In C EOF is not a character, its You seem to have misunderstood Richard O'Keefe's point. By EOF, Richard meant the C #defined constant, normally -1. By , he meant the key you press to send end-of-file (perhaps ^D), which is why he said: >>Let represent your end-of-file character on a UNIX system When you type after a (or another ) it results in read() returning zero, and getc() returning EOF. This is the "normal" use of the key. When you type at other times (eg after typing some letters), it causes the line to be made available for read()ing, just as does. However, there is no \n character (or ^D or whatever) appended to the data. Typing abc results in read() returning 3 and getting the characters 'a', 'b', and 'c'. Thus you can type in something that's a line from the point of view of the tty driver, but doesn't end with '\n' and isn't a line from the point of view of fgets(), which does something like while(--count > 0 && (c = getc(file)) != EOF && c != '\n') completely ignoring the boundaries of data returned by read(). -- Richard -- Richard Tobin, JANET: R.Tobin@uk.ac.ed AI Applications Institute, ARPA: R.Tobin%uk.ac.ed@nsfnet-relay.ac.uk Edinburgh University. UUCP: ...!ukc!ed.ac.uk!R.Tobin