#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main()
{
char arr[11] = { 0 };
int len = sizeof(arr) / sizeof(char);
//从键盘读取十个字符
for (int i = 0; i < len-1; i++)
{
scanf("%c", &arr[i]);
}
int count[26] = { 0 };
printf("%u\n", sizeof(count));
for (int i = 0; i < len; i++)
{
//arr数组中字母的ascII码值减去'a'刚好得到count数组中下标
int index = (int)arr[i] - 'a';
count[index]++;
}
for (int i =0 ; i < 26; i++)
{
if (count[i] != 0)
{
printf("%c字符出现的次数为%d\n", 'a' + i, count[i]);
}
}
system("pause");
return EXIT_SUCCESS;
}
统计字母字符串中字符出现的次数(C语言实现)
最新推荐文章于 2024-04-23 20:07:30 发布