I wrote getnum() to return an integer from stdin:
int getnum(int * last) {
int c, n = 0;
while ((c = getchar()) != EOF && 0x30 <= c && c < 0x40)
n = n * 10 + (c - 0x30);
if (last)
*last = c;
return n;
}
It will get digits from stdin until a non-digit character is retrieved. Because getnum() doesn't care what the non-digit character is, it doesn't matter how the numbers are arranged. They could all be on the same line, or in space-delimited pairs, one per line. I put this in a loop that stops once it reads in the right number of numbers, but you could easily loop until last pointed to non-whitespace.
Additionally, if you want to read from a FILE or fd (integer file descriptor), pass the FILE/fd to getnum() and use getc(FILE *)/fgetc(int).
scanfreturns the number of items successfully read in.