Don't use Scanf()

Kim Kempf kim at mcrware.UUCP
Tue Mar 15 05:27:34 AEST 1988


In article <9241 at sunybcs.UUCP>, ugfailau at sunybcs.uucp (Fai Lau) writes:
>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
>>...
>
>	C'mon!!! Is it really an issue?
>
>>For example:
>>	printf("Hello world!\n");
>
>	I can't imagine any reasonably competant C compiler not
>generating the almost same codes for both cases.
>
The issue here is not the code the compiler generates (its the same in
either case) but the execution time expended.  Given an arbitrary string
to output, printf must look at each character checking for a '%' for
format conversion.  If no format conversions are desired, its much faster
to use puts().  Furthermore, if the conversion string *does* contain
a '%' and is not escaped, watch out!  Consider the following:

	printf("It's 100%unusable!\n");

The output is unexpected at best.



More information about the Comp.lang.c mailing list