使用 isalpha 进行循环验证

Validation using isalpha for a loop

我正在用 C 编写一个程序,其中涉及选择 4 个选项。 但是,我无法验证变量 Option 的值是否为字母或数字,而不是 1、2、3 或 4。当我输入字母时,它继续循环打印语句而不是输入函数,我我无法继续我的计划。 有人可以告诉我我的代码有什么问题吗?

int Option;

while( (Option>4) || ( isalpha(Option) ) )


{

printf("Please select a valid option from the 4 options listed above! \n");

scanf(" %d",&Option);

}

description for the function isalpha() 表示

In the "C" locale, isalpha returns true only for the characters for which isupper or islower is true.

也就是说

isalpha('4') // false
isalpha(4) // false in ASCII-based computers
           // the ASCII table assigns 4 to a control character
isalpha('A') // true
isalpha(65) // true in ASCII-based computers
            // the ASCII table assigns 65 to the symbol 'A'