Validate the type of input in a do-while loop C
问题 Basically, I need to ensure that input is an integer , like so: do { printf("Enter > "); scanf("%d", &integer); } while (/* user entered a char instead of an int */); I have tried various methods, but it always end up with run-time error or infinite loop when I tried to enter a char . I have knew that fflush(stdin) is an undefined behavior, which is better not to involve it in my code in order to prevent any error plus it no longer works in VS2015 due to some reasons. The codes below are the