编写一个函数int ch(char s[ ],char c);求s中c字符出现的次数。

2025-02-28 15:50:43
推荐回答(1个)
回答1:

程序如下:

int ch(char s[], char c)
{
int count = 0;
char *ps = s;
while (*ps != '\0')
{
if (*ps == c)
count++;
ps++;
}
return count;
}

 测试结果如图: