#include <stdio.h>
#include <stdlib.h>
int letter_count=0,num_count=0,other_count=0;
//获取字符串中字母数,数字数,其他字符数
void char_count(char *str){
int i=0;
while(*(str+i) != '\0'){
char c = *(str+i);
if( c >= '0' && c <= '9')
num_count++;
else if( (c >= 'A' && c <='Z') || (c >= 'a' && c <= 'z'))
letter_count++;
else
other_count++;
i++;
}
}
int main() {
char str[50];
gets(str);
char_count(str);
printf("字母数为:%d\t数字数:%d\t其他字符数为:%d\n",letter_count,num_count,other_count);
system("pause");
return EXIT_SUCCESS;
}
【C语言】统计字符数
最新推荐文章于 2023-12-01 19:24:57 发布