字符串-----统计字符串中每个字符出现的次数(区分大小写)

   具体实现如下:

#include <stdio.h>
#include <string.h>
#define MAXSIZE 256


int main()
{
	char str[MAXSIZE];
	gets(str);
//数组count存储每个字符出现的次数
	int count[256] = { 0 };
//字符出现一次则加一
	for (char *p = str;*p;p++)
	{
		count[*p]++;
	}
//当出现次数大于零时,将各个字符出现的次数打印出来
	for (int i = 0;i < 256;i++)
	{
		if (count[i] > 0)
			printf("The count of %c is : %d\n", i, count[i]);
	}
	return 0;
}

猜你喜欢

转载自blog.csdn.net/weixin_39916039/article/details/81538303