Don't use Scanf()
Richard Tobin
richard at aiva.ed.ac.uk
Fri Mar 18 07:16:01 AEST 1988
In article <1140 at csun.UUCP> sef at csun.UUCP (Sean Fagan) writes:
>Yes, it can be; since printf(3) is interpreted, it *WILL* be slower than
>directly coding the correct statements. I.e., printf("Hello world!\n") is
>slower than puts("Hello world!") which is slower than
>write(1,"Hello world!\n",13). If you're doing a lot of I/O like this, it can
>be significantly slower.
The key phrase here is "If you're doing a lot of I/O like this". You would
certainly have to execute this statement a large number of times for the
interpretation to take longer than counting the characters in the string
(maybe I just don't count fast :-).
The computer's time is much less valuable than mine (to me, at least), so
except in very rare circumstances I'm not going to think about how hard it
is for the computer. I'm quite happy to put 'printf("\n")' in my programs,
especially when it's surrounded by other calls to printf.
Of course, printf() vs write() is also a portability question, but I'm sure
there will be plenty of comments on that...
-- Richard
--
Richard Tobin, JANET: R.Tobin at uk.ac.ed
AI Applications Institute, ARPA: R.Tobin%uk.ac.ed at nss.cs.ucl.ac.uk
Edinburgh University. UUCP: ...!ukc!ed.ac.uk!R.Tobin
More information about the Comp.lang.c
mailing list