#include <stdio.h>
#include <stdlib.h>
//统计字符串字符个数
int upcount=0,lowcount=0,spacecount=0,numcount=0,othercount=0;
void char_total(char *str){
int i=0;
while(*(str+i) != '\0'){
if(*(str+i)>= 'A' && *(str+i)<='Z'){
upcount++;
}else if(*(str+i)>= 'a' && *(str+i)<='z'){
lowcount++;
}else if(*(str+i)>= '0' && *(str+i) <= '9'){
numcount++;
}else if(*(str+i)== ' '){
spacecount++;
}else{
othercount++;
}
i++;
}
}
int main() {
char str[30];
gets(str);
char_total(str);
printf("大写字母个数:%d\n小写字母的个数%d\n空格的个数:%d\n数字字符的个数:%d\n其他字符的个数%d\n",upcount,lowcount,spacecount,numcount,othercount);
return EXIT_SUCCESS;
}
【C语言】统计字符数
最新推荐文章于 2022-10-20 00:42:36 发布