Probably an easy or dumb question
Dwight Kelly
dkelly at npiatl.UUCP
Sat Aug 12 00:02:16 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);
>
Not possible. Scanf reads the variable addresses off of the stack. In your
example, it would get the address of d[0] and then get three random addresses
for the next three %d.
One solution is:
scanf("%d %d %d %d", &d[0], &d[1], &d[2], &d[3]);
or:
int i;
for (i=0; i<4; i++)
scanf("%d", &d[i]);
--
Dwight Kelly UUCP: gatech!npiatl!dkelly
Director R&D AT&T: (404) 962-7220
Network Publications, Inc 2 Pamplin Drive Lawrenceville, GA 30245
Publisher of "The Real Estate Book" nationwide!
More information about the Comp.lang.c
mailing list