Probably an easy or dumb question

Doug Gwyn gwyn at smoke.BRL.MIL
Fri Aug 11 01:16:18 AEST 1989


In article <1949 at leah.Albany.Edu> rds95 at leah.Albany.Edu (Robert Seals) writes:
>int    d[4];
>scanf("%d %d %d %d", d);

Since the array name "d" is converted to "pointer to element d[0]"
before being passed to scanf(), the question answers itself.  d[0]
is a single int.  scanf() can't tell the difference between ways
of producing pointers-to-int that it is fed as arguments; they all
look the same to it.

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

The format string and the input data determine how many items
scanf() actually converts.  Correct usage requires that you provide
one pointer argument for each potentially converted item, i.e. the
remaining arguments must exactly correspond to the format string.



More information about the Comp.lang.c mailing list