mardi 9 novembre 2021

Is there a way how to check if input I have scanfed is a number? With IF function in C?

I need to input 1 to 3 numbers with values between 3 to 69 only. So when I input something different from a number the program should fprintf on stderr "The input isn't number". But I cannot find a way how to code that. And I should use if function.

     #include <stdio.h>

int main()
{
int i=0;

while (scanf("%d", &i) == 1)
{
    
    if (i<3 || i>69)
    {
    fprintf(stderr,"Error: Input is too big or too small!");

    return 101;
    }
    if (ISNT A NUMBER)
    {
    fprintf(stderr,"Error: Input isnt a number!");

    return 100;
    }
}
 
return 0;

}

Aucun commentaire:

Enregistrer un commentaire