Path: utzoo!utgpu!water!watmath!clyde!ima!haddock!karl From: karl@haddock.ISC.COM (Karl Heuer) Newsgroups: comp.lang.c Subject: Re: printf vs fprintf Message-ID: <4151@haddock.ISC.COM> Date: 23 May 88 23:13:09 GMT References: <2454@ritcsh.UUCP> <200@proxftl.UUCP> Reply-To: karl@haddock.ima.isc.com (Karl Heuer) Organization: Interactive Systems, Boston Lines: 18 In article <200@proxftl.UUCP> jesse@proxftl.UUCP (Jesse Perry) implores people not to use scanf(). To avoid misunderstandings, I would rephrase it thus: The scanf() family is for *free-format* input -- non-significant whitespace, including newline, tends to be ignored. If you need line-oriented (e.g. prompted) input, you probably want to use something else. >Using (f)gets() followed by sscanf() is much more reliable, since format >errors can be detected and reported immediately. Let me add that fgets() is better than gets() in that it does bounds-checking (but even so, programs seldom do anything reasonable when it is detected). Also, when using fgets/sscanf it's easy to overlook the error of having *too much* data on one input line -- one way to catch this is to put " %c" at the end of the format (and an appropriate dummy variable in the arglist), and expect the return value to be one *less* than the number of variables passed. Karl W. Z. Heuer (ima!haddock!karl or karl@haddock.isc.com), The Walking Lint