查找字符串中每个字符出现的个数

来源:互联网 发布:网络主播毒害中国 编辑:程序博客网 时间:2024/06/05 13:29

*开辟数组空间来存储字母的出现个数*

#include <stdio.h>

void AppearCount(char *str)
{
static int count[256]={0};
while(*str)
{
count[*str]++;
str++;
}
for(int i=0;i<256;i++)
{
if(count[i]!=0)
printf("字母%c出现的次数为%d.\n",i,count[i]);
}
}
int main()
{
char str[40]="qishiwoshiyigeyanyuan";
AppearCount(str);
return 0;
}
0 0
原创粉丝点击