I do not know much about the sscanf function, but what I am trying to do is iterate through a line of integers. Given the variable
char *lineOfInts
>
You can use strtol in a loop until you don't find the NUL character, if you need to store those numbers use an array:
#include
#include
#define MAX_NUMBERS 10
int main(void)
{
char *str = "12 45 16 789 99";
char *end = str;
int numbers[MAX_NUMBERS];
int i, count = 0;
for (i = 0; i < MAX_NUMBERS; i++) {
numbers[i] = (int)strtol(end, &end, 10);
count++;
if (*end == '\0') break;
}
for (i = 0; i < count; i++) {
printf("%d\n", numbers[i]);
}
return 0;
}