Don't use Scanf()

Greg Pasquariello X1190 gp at picuxa.UUCP
Wed Mar 23 22:26:21 AEST 1988


In article <9241 at sunybcs.UUCP>, ugfailau at sunybcs.UUCP writes:
> In article <1185 at ucsfcca.ucsf.edu> roland at rtsg.lbl.gov (Roland McGrath) writes:
> >For example:
> >	printf("Hello world!\n");
> >Haven't you ever heard of puts????
> >	puts("Hello world!");	/* note the newline is appended	*/
> 
> 	I can't imagine any reasonably competant C compiler not
> generating the almost same codes for both cases.




	These are library calls, and although the compiler will generate
approximately the same function calling sequence, the linker will link in 
a much larger function in printf().



> 	Let's face it. The best way to give efficiency to a program
> is to write your own macro to handle file I/O and strings. Macros like
> strcpy are too general if you want to be picky. 
> 	For example, if you want to print a string fast, you would write
> a routine that uses only putc with no format capacity and no error
> checking whatsoever, and forget about printf. 




	That is about what puts() does!  However, rather than looping on
putc(), the string is put directly into the buffer with memcpy(), which is
quicker.


Greg Pasquariello
ihnp4!picuxa!gp



More information about the Comp.lang.c mailing list