请编写相关函数来完成对一段英文字符串进行字母统计功能,出现最多那个字母的出现次数,不区分大小写。

思路:
1、对字符串进行过滤,把英文字母过滤出来。
2、将所有英文字母统一转成小写(大写)。
3、将待求的字符串与26个字母进行比较并统计个数
4、统计出现最多的字母。

源代码:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char s_str[] = "abcdefghijklmnopqrstuvwxyz";
int GetEngCount(char* szStr, char c)
{
int i = 0;
int EngCount = 0;
while(*(szStr+i) != '\0')
{
if((szStr[i] >= 'a' && szStr[i] <= 'z') || (szStr[i] >= 'A' && szStr[i] <= 'Z'))
{
if(szStr[i] >= 'A' && szStr[i] <= 'Z')
{
szStr[i] = szStr[i]+32;
}
if(szStr[i] == c)
{
EngCount++;
}
}
i++;
}
return EngCount;
}
char GetMaxCountChar(char *szSrc, int index)
{
int iPos = 0;
int iMaxCount;
while(*(s_str+index) != '\0')//定位标志的字符串
{
int iCount = GetEngCount(szSrc, s_str[index]);
if(iMaxCount <= iCount)
{
iMaxCount = iCount;
iPos = index;
}
index++;
}
return s_str[iPos];
}
int main(int argc, char* argv[])
{
int index = 0;
char str[] = "a.gAg.Vg.wgwh,,fgpg@g2g0\80k+6*1g87&37pge";
printf("%s 字符中出现最多的字母为: %c\r\n", str, GetMaxCountChar(str, index));
return 0;

}


  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值