I am writing a program in CodeBlocks in C. I want to check if the input is in the right type and if not try to get it again.
My problem is whenever I'm trying to get the input with scanf and the input is incorrect it won't enter scanf again and just keep looping as if the input is always incorrect.
#include <stdio.h>
#include <stdlib.h>
int main()
{
float a = 0;
while(scanf(" %f", & a) == 0)
{
printf("reenter");
}
printf("%f", a);
return 0;
}
When I tried to enter incorrect value as 'y' the loop will go on:
If I will enter a current value it will get it as it should.