I have a problem with scanf in while loop. Made a simple piece of code for illustration:
#include <stdio.h>
int main() {
int menu = 0;
while (menu != -1) {
if (!scanf("%d", &menu)) printf("n/a\n");
}
return 0;
}
If I enter an improper data like char in stdio, scanf doesn't stop the cycle for input and program just typing n/a over and over. With integers, it works properly: awaiting for input in every iteration. Can someone explain this behavior?