首页 > 编程语言 > 详细

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

时间:2021-08-06 17:54:25      阅读:41      评论:0      收藏:0      [点我收藏+]
 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 }

 

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

原文:https://www.cnblogs.com/chenweiweb/p/15108123.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!