请制作包含文字列里的特定字符数量的函数int str_chr(char*s,intc)。s是文字列,c是存储单元字符的个数

图片说明

输入字符串:i am a boy
输入存储单元字符的个数:k
k的个数:0

输入字符串:i am a boy
输入存储单元字符的个数:a
a的个数:2

#include <stdio.h>
int str_chr(char*s,int c)
{
int x = 0;
for (int i = 0; s[i]; i++)
if (s[i] == c) x++;
return x;
}
int main()
{
char ch[1000];
printf("输入字符串:");
scanf("%[^\n]", ch);
char f;
printf("输入存储单元字符的个数:");
scanf("%c", &f);
int x = str_chr(ch, f);
printf("%c的个数:%d", f, x);
return 0;
}

https://ask.csdn.net/questions/1082387 这个问题如果解决,请采纳下,谢谢