您的位置:首页 > 编程语言 > C语言/C++

【C语言】统计字符数

2016-05-16 11:56 323 查看
#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语言