希玄 2023-12-06 12:33 采纳率: 45%
浏览 5
已结题

设计程序,利用函数getCharacterCnt,实现求解出str所指字符串中指定字符的个数,并返回此值。

img


设计程序,利用函数getCharacterCnt,实现求解出str所指字符串中指定字符的个数,并返回此值。

  • 写回答

9条回答 默认 最新

  • 专家-赤兔[在线] 优质创作者: 编程框架技术领域 2023-12-06 12:33
    关注
    #include <stdio.h>
    
    int getCharacterCnt(char *str, char c) {
        int count = 0;
        while (*str != '\0') {
            if (*str == c) {
                count++;
            }
            str++;
        }
        return count;
    }
    
    int main() {
        char str[1000000];
        char c;
        fgets(str, sizeof(str), stdin);
        scanf("%c", &c);
        int cnt = getCharacterCnt(str, c);
        printf("%d", cnt);
        return 0;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论 编辑记录
查看更多回答(8条)

报告相同问题?

问题事件

  • 系统已结题 12月14日
  • 已采纳回答 12月6日
  • 创建了问题 12月6日