Check if User Inputs a Letter or Number in C

后端 未结 7 1433
终归单人心
终归单人心 2020-12-03 15:22

Is there an easy way to call a C script to see if the user inputs a letter from the English alphabet? I\'m thinking something like this:

if (variable == a -          


        
相关标签:
7条回答
  • 2020-12-03 16:25

    Aside from the isalpha function, you can do it like this:

    char vrbl;
    
    if ((vrbl >= 'a' && vrbl <= 'z') || (vrbl >= 'A' && vrbl <= 'Z')) 
    {
        printf("You entered a letter! You must enter a number!");
    }
    
    0 讨论(0)
提交回复
热议问题