Newsgroups: comp.lang.c Path: utzoo!henry From: henry@zoo.toronto.edu (Henry Spencer) Subject: Re: What's so bad about scanf anyway??? Message-ID: <1990Nov13.193219.8708@zoo.toronto.edu> Organization: U of Toronto Zoology References: <16582@netcom.UUCP> Date: Tue, 13 Nov 90 19:32:19 GMT In article <16582@netcom.UUCP> avery@netcom.UUCP (Avery Colter) writes: >In the self-teaching course I have here, scanf is the most often used >input function. I don't see gets used much at all. It is not surprising that an introductory course will focus on doing things the easy way rather than the better but more complex way, for the sake of not confusing beginners. As others have discussed at length, the problem with scanf is a poor and inflexible design that gives you little control over the situation when unexpected input is encountered. Pulling in a line with fgets (not gets!) and then picking it apart with sscanf makes clean error recovery much easier. >I didn't see puts used for printing strings to screen much either. >printf was the function of choice. People frequently draw this analogy, but it is false and misleading. Printf works very well for output because its inputs are C data, very tightly constrained by the language and the machine, and the free-form version is what it is *generating*. The situation is not symmetrical; scanf is faced with a very different and much harder problem. -- "I don't *want* to be normal!" | Henry Spencer at U of Toronto Zoology "Not to worry." | henry@zoo.toronto.edu utzoo!henry