scanf()
.fgets()
to get an entire line.strtol()
to parse the line as an integer, checking if it consumed the entire line.char *end;
char buf[LINE_MAX];
do {
if (!fgets(buf, sizeof buf, stdin))
break;
// remove \n
buf[strlen(buf) - 1] = 0;
int n = strtol(buf, &end, 10);
} while (end != buf + strlen(buf));