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

关注#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;
}