Originally Posted by
Creedy
Wouldn't it scan the whole thing into just a[0]?
That's an easy thing to check:
Code:
#include <stdio.h>
int main(void) {
int a[5];
scanf("%d", &a[0]);
printf("You entered %d\n", a[0]);
return 0;
}
Type in a bunch of numbers and see what happens.
Originally Posted by
Creedy
I'm not sure whether or not it will keep track of the spaces compared to which slot of the array it needs to be stored in.
To expand on what I meant, you would presumably use fgets or something similar to read in an entire line, then use sscanf to read from that line in a loop. (If you put plain old scanf in a loop, then your user would have to hit EOF or something similar to make the loop stop, or type in a special "sentinel" value, or just generally do something special to make the reading stop.)