I've been trying to implement a protective measure for my scanf() functions in my program.
The goal is to get the input from the user, and then ask again if scanf doesn't successfully receive input. The problem here is is that when a user give the program bad input, (Like, a character for instance) the while loop just prints the "enter the integer" message on to infinity and doesn't re-evaluate the input.
printf("Enter an integer to be added to\n");
while (scanf("%d", &a) != 1);
printf("Enter a second integer to be added to the first\n");
while (scanf("%d", &b) != 1);
c = (a + b);
printf("%d + %d = %d\n", a,b,c);