Don't use Scanf()

mike knudsen knudsen at ihwpt.ATT.COM
Tue Mar 1 05:55:23 AEST 1988


Don't use Scanf() from the C Standard Library if you care
about the size of your object program.  It uses 5K
(yes, 5000 bytes) of text space, plus over 200 bytes of Data.
Ripping it out of my huge music editor really opened things
up for new features this weekend.
[Above figures are for Microware OS9 6809 C library].

It's well worth writing your own code to do simple parses.
Among the string functions, try Index(char, string) which
will find commas and such in the input.
Input is best got from gets(string).

Besides, scanf() has always been hostile to users who don't
type in just the right stuff.  If you need it for user-friendly
stuff use gets(string) followed by sscanf(string).

Note: "string" means "(char *)" or "char[]" in the above.
PS: Printf() is probably just as big, but usually harder to
do without, especially in a big program.
-- 
Mike J Knudsen    ...ihnp4!ihwpt!knudsen  Bell Labs(AT&T)
    Delphi: RAGTIMER    CIS: <memory failure, too many digits>
	"Just say NO to MS-DOS!"	"OS/2 == 1/2 of an OS"



More information about the Comp.lang.c mailing list