I suggest using
while(!feof(stdin) && scanf ( "%d %d ", &a, &b) == 2)
and actually it's better to check feof after (not earlier!) some input operation, therefore:
while (scanf("%d %d ", &a, &b) == 2 && !feof(stdin))
BTW, many stdin systems support line buffering, at least via interactive terminals (but maybe not when stdin is pipe (7) ), see setvbuf (3)
On Linux and POSIX, you can look at each line using getline (3) (or even readline (3) when reading from the terminal, because readline offers editing options), then parse this line, for example sscanf (3) (possibly also using %n ) or strtol (3)
source share