C语言练习-终端读取字符并判断

 1 /*
 2  *author:余性笃厚
 3  *description:从终端读取字符判断其时字母(大小写)、数字、标点符号
 4  *要求:使用ctypt.h头文件中的相关原型函数
 5 
 6 */
 7 #include <stdio.h>
 8 #include <ctype.h>
 9 
10 int main(void) {
11     char ch;
12     printf("Please input a characer:");
13     scanf("%c",&ch);
14     if (isalpha(ch)) { //判断字母
15         if (islower(ch)){ //小写
16             printf("You input a lower\n");
17             printf("Upper(%c):%c", ch, toupper(ch));
18         }
19         else { //大写
20             printf("You input a Upper\n");
21             printf("Upper(%c):%c", ch, tolower(ch));
22         }
23     }
24     else if(isdigit(ch)){ //判断数字
25         printf("You enter a digit\n");
26     }
27     else if (ispunct(ch)) { //判断标点符号
28         printf("You enter a punctuation character\n");
29     }
30     else if (isspace(ch)) { //判断空白字符
31         printf("You enter a whitespace character\n");
32     }
33     else { //输入其它字符
34         printf("You enter a unknow character!\n");
35     }
36     return 0;
37 }

 

posted @ 2021-08-06 13:39  余性笃厚  阅读(154)  评论(0)    收藏  举报