Probably an easy or dumb question

Jeff Aguilera jeffa at hpmwtd.HP.COM
Fri Aug 11 08:59:58 AEST 1989


> 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);
> 

No.  Use

 scanf("%d %d %d %d", d, d+1, d+2, d+3);

For each valid conversion specification other than %%, at least one pointer 
is consumed from the stack.  You pass one pointer, but ask for four 
conversions.  Expect a hung system or dumped core, depending upon available
memory protection.



More information about the Comp.lang.c mailing list