Use fgets() to read a full line, then parse the line (possibly with strtol()).
#include <stdio.h>
#include <stdlib.h>
int main(void) {
char buffer[10000];
char *pbuff;
int value;
while (1) {
if (!fgets(buffer, sizeof buffer, stdin)) break;
printf("Line contains");
pbuff = buffer;
while (1) {
if (*pbuff == '\n') break;
value = strtol(pbuff, &pbuff, 10);
printf(" %d", value);
}
printf("\n");
}
return 0;
}
You can see the code running at ideone.