Home >Backend Development >C#.Net Tutorial >When entering a character, how to determine whether it is a letter, number or special character?
How to determine if a character is a letter, number or special character
The method is as follows:
1. Use format Use the symbol %c to get the input character;
2. Just determine the position of the character in the ascii code table.
#include <stdio.h> int main(){ char ch; printf("请输入一个字符"); scanf("%c",&ch); if(ch >= 'a' && ch <= 'z' || ch >= 'A' && ch <= 'Z'){ //字母的取值范围 printf("%c是一个字母\n",ch); }else if(ch >= '0' && ch <= '9'){ //数字的取值范围 printf("%c是一个数字\n",ch); }else{ printf("%c是一个特殊字符\n",ch); } return 0; }
PHP Chinese website, a large number of Introduction to Programming Tutorials, welcome to learn!
The above is the detailed content of When entering a character, how to determine whether it is a letter, number or special character?. For more information, please follow other related articles on the PHP Chinese website!