Originally Posted by
mangekyou
If I write 123456 or 1 2 3 4 5 6 or 1,2,3,4,5,6 and press enter. Or
1 (I press enter)
2 (enter)
....
Is there a way I can catch every single digit and store them as an int? If so, what is that called? I dont need the code, I just want to know what its called so I can read about it, but example code will be appreciated
For "1 2 3 4 5 6" and "1,2,3,4,5,6" you can use a single scanf() call (scanf from scan function):
Code:
int a[6];
scanf("%d %d %d %d %d %d", &a[0], &a[1], &a[2], &a[3], &a[4], &a[5]); // if separated by spaces
scanf("%d,%d,%d,%d,%d,%d", &a[0], &a[1], &a[2], &a[3], &a[4], &a[5]); // if separated by commas.
In the first case, scanf() doesn't care if you type the values individually or not... In the second case, you must type the commas.
If you type all values together, you must separate them by yourself (scanf() thinks 123456 is a single integer).
Of course, if you have a variable quantities of numbers, using scanf() in a loop is a good idea if they are separated.