字母表是从 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: fthis is an alphabet
输出enter a character: rthis is an alphabet
输出enter a character: 7this is a number
输出enter a character: #this is a special character
以上就是检查输入字符是字母、数字还是特殊字符在c中的详细内容。
