I\'ve a small C-program which just reads numbers from stdin, one at each loop cycle. If the user inputs some NaN, an error should be printed to the console and the input pro
scanf()
leaves the "a
" still in the input buffer for next time. You should probably use getline()
to read a line no matter what and then parse it with strtol()
or similar instead.
(Yes, getline()
is GNU-specific, not POSIX. So what? The question is tagged "gcc" and "linux". getline()
is also the only sensible option to read a line of text unless you want to do it all by hand.)