/*
*author:余性笃厚
*description:从终端读取字符判断其时字母(大小写)、数字、标点符号
*要求:使用ctypt.h头文件中的相关原型函数
*/
#include <stdio.h>
#include <ctype.h>
int main(void) {
char ch;
printf("Please input a characer:");
scanf("%c",&ch);
if (isalpha(ch)) { //判断字母
if (islower(ch)){ //小写
printf("You input a lower\n");
printf("Upper(%c):%c", ch, toupper(ch));
}
else { //大写
printf("You input a Upper\n");
printf("Upper(%c):%c", ch, tolower(ch));
}
}
else if(isdigit(ch)){ //判断数字
printf("You enter a digit\n");
}
else if (ispunct(ch)) { //判断标点符号
printf("You enter a punctuation character\n");
}
else if (isspace(ch)) { //判断空白字符
printf("You enter a whitespace character\n");
}
else { //输入其它字符
printf("You enter a unknow character!\n");
}
return 0;
}
C语言练习-终端读取字符并判断
最新推荐文章于 2021-11-24 11:09:28 发布