检查输入字符是字母,数字还是C中的特殊字符
在本节中,我们将看到如何检查给定字符是数字,还是C中的字母或某些特殊字符。
字母从A–Z和a–z,然后数字从0–9。所有其他字符均为特殊字符。因此,如果我们使用这些条件检查条件,则可以轻松找到它们。
示例
#include <stdio.h>
#include <conio.h>
main() {
char ch;
printf("Enter a character: ");
scanf("%c", &ch);
if((ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z'))
printf("This is an alphabet");
else if(ch >= '0' && ch <= '9')
printf("This is a number");
else
printf("This is a special character");
}输出结果
Enter a character: F This is an alphabet
输出结果
Enter a character: r This is an alphabet
输出结果
Enter a character: 7 This is a number
输出结果
Enter a character: # This is a special character
热门推荐
10 儿子立冬祝福语简短独特
11 对当兵的祝福语简短
12 侄儿高考试祝福语简短
13 伴郎红包祝福语朋友简短
14 媳妇生日简短祝福语朋友
15 公司年会祝福语简短最好
16 元旦感恩祝福语简短大全
17 红包祝福语简短10字
18 周六早晨祝福语简短