Probably an easy or dumb question

Chris Torek chris at mimsy.UUCP
Fri Aug 11 19:25:19 AEST 1989


In article <1949 at leah.Albany.Edu> rds95 at leah.Albany.Edu (Robert Seals) writes:
>Hello frenz, is it workable to pass only the base address of an array
>to "?scanf" and have it convert into successive memory locations?
>
>int    d[4];
>
>scanf("%d %d %d %d", d);

Easy, yes; dumb, no: but the answer is no.

>I guess the question is whether "scanf" uses the format string or
>the number of arguments to determine how many thingies to convert.
>So, what is it?

It uses the format.  In particular, the proposed ANSI C standard says
that printf et al. can be given `extra' arguments, so these clearly
must use the format rather than (or perhaps in addition to) the
number and types of arguments; and given that, it is likely that
the same will be true of scanf, whether or not it is required (I
cannot recall offhand).

In any case, even if it used the number of arguments,

	scanf("%d %d %d %d", d);

would still pass only two arguments, one being a pointer to
char that points to the first `%', and the other being a pointer
to int that points to d[0].
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163)
Domain:	chris at mimsy.umd.edu	Path:	uunet!mimsy!chris



More information about the Comp.lang.c mailing list