Home > Backend Development > C#.Net Tutorial > When entering a character, how to determine whether it is a letter, number or special character?

When entering a character, how to determine whether it is a letter, number or special character?

angryTom
Release: 2020-03-18 16:00:32
Original
17407 people have browsed it

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 >= &#39;a&#39; && ch <= &#39;z&#39; || ch >= &#39;A&#39; && ch <= &#39;Z&#39;){
        //字母的取值范围
        printf("%c是一个字母\n",ch);
    }else if(ch >= &#39;0&#39; && ch <= &#39;9&#39;){
        //数字的取值范围
        printf("%c是一个数字\n",ch);
    }else{
      printf("%c是一个特殊字符\n",ch);
    }
    return 0;
}
Copy after login

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template