Re^2: scanf(..)

Peter da Silva peter at ficc.uu.net
Tue Jun 13 23:13:19 AEST 1989


scs at adam.pika.mit.edu (Steve Summit) writes:
>It is only a miserable problem when scanf
>is being used for interactive user input, which is what everybody
>uses it for.

Anyone using scanf directly for interactive input... or for any input at
all... should have their head examined.

The only really safe way to use scanf() without freaking out the casual
user of your code is to do something like this:

	fgets(buffer, sizeof buffer, stdin);
	sscanf(buffer, fmt, args...);

Sure, you can probably cons up a format string that does what you want, but
who needs the aggravation?

[ By the way, it really bugs me that stdio is so inconsistant about the
  position of the inevitable 'stream' argument? In an ideal world that code
  would read "fgets(stdin, buffer, sizeof buffer)", no? ]

-- 
Peter da Silva, Xenix Support, Ferranti International Controls Corporation.

Business: uunet.uu.net!ficc!peter, peter at ficc.uu.net, +1 713 274 5180.
Personal: ...!texbell!sugar!peter, peter at sugar.hackercorp.com.



More information about the Comp.lang.c mailing list