This question has been asked before, but i've never found a clear and simple answer, so i'm asking it again...
I'de like to know, without using any other library than stdio.h, how to check if what the user has entered is a numeric value or not. Basically, the user is asked to enter a value between 0 and 9. If the number is between those two, it continues. If the number is 12 for example, it loops back to the question and asks for the number again.
It works fine, except that if i enter a letter OR a decimal number, it enters into an infinite loop...
Basically here is my question: how can i check that the value entered is not a character and non decimal?
Here is the beginning of the code: (sorry, its in french, but you get the idea...)
int main()
{
int nb1, nb2, rand_1, rand_2;
int nb_coups = 0;
int points = 0;
printf("\n\n ------ BIENVENUE A LA GRANDE ROUE ! ------\n\n");
do{
//Saisie 1er nombre
printf("Entrez le premier nombre choisi (entre 0 et 9) : ");
scanf("%d",&nb1);
//Tant que le 1er nombre n'est pas compri entre 0 et 9, on le redemande
while(nb1<0 || nb1>9)
{
printf("Nombre incorrect. Entrez le premier nombre choisi (entre 0 et 9) : ");
scanf("%d",&nb1);
}
//On affiche le 1er nombre
printf("Le nombre choisi est : %d\n\n",nb1);