I have a very short snippet that reads in an integer:
#include
int main() {
while (1) {
int i = 0;
int r = scanf(\"%d\",
Man page says
RETURN VALUES These functions return the number of input items assigned. This can be fewer than provided for, or even zero, in the event of a matching failure. Zero indicates that, although there was input available, no conversions were assigned; typ- ically this is due to an invalid input character, such as an alphabetic character for a `%d' conversion.
Since you have used "%d" , if you use any number then this will work fine otherwise it will not consume it from the buffer