edit1: Sorry, I am in an intro to programming class... I read the two links, but don't fully understand them...
I tried to to add
if (scanf_s("%d", &input) == 0) {
fflush(stdin);
continue;
}
but that didn't seem to do anything. I understand that scanf is in an error state, so it will refuse to run, and that I need to clear a buffer of the bad input from user.
so basically, I am looking for a beginner's solution, for someone who just learned about loops, input/output, and basic error check.
~~~~~~~~~
I am new to C and have a small question. I want to read a list of integers from the console. It works fine if the user does indeed input integers, but if it types something like "acdb", or "0.5", I just get the program printing "enter a number: " infinitely, as if it's running the loop but scanf_s is broken and so it just skips itself.
Thanks for your help.
int input = 1;
while (input != 0) {
printf("enter a number: \n");
scanf_s("%d", &input);
/* rest of code omitted */
}