Don't use Scanf()

Johan Vromans jv at mhres.mh.nl
Sun Mar 13 00:00:25 AEST 1988


In article <1185 at ucsfcca.ucsf.edu> roland at rtsg.lbl.gov (Roland McGrath) writes:
>One real stupidity I've seen many, many times is the
>over-use of printf.  The printf functions have their uses,
>and they do their job quite well, but please know what these
>uses are!!
>
> [examples of using puts, fput, putc instead of printf]
>
>And the ultimate stupidity:
>	printf("\n");
>Get a brain!!!!!  You're using the function that can do complex
>data formatted output to write one bleeping character!!!!!
>Try
>	putchar('\n');
>If you include <stdio.h>, this will probably end up being a macro
... If you don't you will likely end up with a missing routine ...
>that will write it out very fast.

Yes. But it does not flush if the output is a terminal or line-buffered.

>In general, if there's no format spec, don't use printf!!!!!!

I partly agree. When you are short on space, and want to eliminate the use
of "large" routines like printf, you are right.
On the other hand, you suggest the use of four or five different routines
(with all different calling sequences) instead of one simple and elegant
"printf" routine. Printf *CAN* do complex formatting, but it *DOESN'T* do
this if you don't have format strings. What remains is just the tiny
overhead of testing whether there are formatting characters in the string...

I dislike discussions in which the quality of the arguments is measured by the
number of exclamation marks following each sentence.


-- 
Johan Vromans                              | jv at mh.nl via European backbone
Multihouse N.V., Gouda, the Netherlands    | uucp: ..{uunet!}mcvax!mh.nl!jv
"It is better to light a candle than to curse the darkness"



More information about the Comp.lang.c mailing list