I have a C programming assignment that wants me to take multiple numbers space-seperated inputs and store them in array, at the beginning.
Input sample is like:
X 18 34 5
Y 34 56 7
r 10 23 2
The number of lines can be more than that and also spaces between those numbers which are on one line can be more than one.(For example: 23_34 or 23______34)
After taking input i need to hold 3. arr1 = consist of first values of each input), arr2 = consists of second values of each input and arr3 = from first to third values of each input. If i can take the input and assign them temporary variables, i can overcome to put them in the arrays.
I have checked many discussions but none of post could solve my problem.
Probably while(c = getchar() != EOF)
can be a solution for this but i couldn't get the logic behind it and also write it properly..
Edit: This is my code
char a;
int b,c,d;
while ((a = getchar()) != EOF){
ungetc(a,stdin);
scanf("%c %d %d %d",&a,&b,&c,&d);
printf("%c %d %d %d\n",a,b,c,d);
Why this code prints also previous values? (click to see the image)