从控制台输入一个字符串,长度与内容自定。统计各个字母在字符串中出现的次数。要求:1) 声明一个并在main()函数中调用,该函数实现对字母出现次数的统计,其参数包含一个字符指针;2) 不允许使用数组下标访问数组元素或为数组元素赋值;3) 忽略大小写;4) 仅需输出字符串中曾经出现过的字母的统计结果
3条回答 默认 最新
- 浪客 2022-03-11 13:37关注
#include <stdio.h> int word[26]= {0}; void tong(char *s) { while(*s) { if(*s>='a' && *s<='z') (*(word+(*s-'a')))++; else if(*s>='A' && *s<='Z') (*(word+(*s-'A')))++; s++; } } int main() { char s[100]; gets(s); tong(s); for(int i=0; i<26; i++) { if(*(word+i)>0) { printf("%c %d\n",'a'+i,*(word+i)); } } return 0; }
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 2无用