#include <stdio.h>
int main(void)
{
int i;
while (1)
{
if (scanf("%i", &i) == 1)
{
break;
}
fflush(stdin);
}
}
This code is supposed to ask the user for input until they input an integer, but it only works if the user inputs an integer in the first iteration. If the user first inputs a character, for example, then an integer, the loops continues iterating.
The only answer I have found to my problem said using fflush(stdin)
should work, but it doesn't.