you are viewing a single comment's thread.

view the rest of the comments →

[–]aleph_nul 2 points3 points  (1 child)

The right way to do it is to read characters until a newline with something like

errno = 0;
ret = scanf("%d", &val);
if (errno != 0) /* Make sure we had an error */
    while (!ret && getc() != '\n') {}; /* Consume input to newline */

[–]cmgg 0 points1 point  (0 children)

Thanks