/* 输入一行文字,找出其中大写字母、小写字母、空格、数字以及其他字符各有多少 */ #include<stdio.h> #include<string.h> int main() { char buf[1024]; printf("请输入一个字符串:\n"); gets(buf); int upper_count = 0,lower_count = 0,digit_count = 0,space_count = 0,other_count = 0; char *prt = buf; while(*prt != '\0'){ if(*prt>='A'&&*prt<='Z'){ upper_count++; }else if(*prt>='a'&&*prt<='z'){ lower_count++; }else if(*prt>='0'&&*prt<='9'){ digit_count++; }else if(*prt==' '){ space_count++; } else{ other_count++; } prt++; } printf("大写字母:%d,小写字母:%d,数字:%d,空格:%d,其他:%d",upper_count, lower_count, digit_count, space_count, other_count); }
0.0分
0 人评分