[英]Also convert upper case to lower case to count
我有一个代码,可以使它遍历名称列表并计算使用字母的次数。 到目前为止,它适用于小写字母,但如何在图片中实现大写字母。 我非常感谢您的帮助。
/*
* Search through each character in s,
* which is array containing n strings,
* and update the global count array
* with the correct character counts.
* Note: check the examples to see
* if the counts should be case
* sensitive or case insensitive.
*/
void letterCount(char * s[], int n){
//Implement this function
int c = 0,x,i;
char p = 'a', j = 'z', A = 'A', Z = 'Z';
while (c<n) {
for(i=0;s[c][i]!='\0';i++){
if (s[c][i] >= p && s[c][i] <= j ){
x = s[c][i] - 'a';
count[x]++;
}
c++;
}
}
}
您可以设置字母大小写的条件,即仅使用小写或大写字母。 将字符数组的内容转换为小写(通过将每个字符的值(ASCII VALUE)增加32),然后调用letterCount
函数。 或使用strlwr
将字符串转换为小写。
您可以使用如下ascii值:az的count1 []和AZ的count2 []
if((s[c][i] >= 97 && s[c][i] <= 122))
{
x = s[c][i] - 'a';
count1[x]++;
}
if( (s[c][i] >= 65 && s[c][i] <= 90)))
{
x = s[c][i] - 'A';
count2[x]++;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.