I want to check the user input if it is a number and I want the program to accept only a number as an input. I don't know if I explained myself clearly, I'll try by showing you an example:
int x;
printf("Write a number: ");
scanf("%d", &x);
while(!isdigit(x))
{
printf("Not valid\n");
fflush(stdin);
scanf("%d", &x);
}
I tried using scanf("%d", &x) != 1
as a while condition but it remains inside the loop. Is there a way to ask an input until the user writes a number? For now I just return the function but I'd like not to.