#include <iostream>
#define M 81
using namespace std;
int fun(char* ss, char c)
{
int i, j = 0;
for (i = 0; i < strlen(ss); i++)
{
if (*(ss + i) == c)j++;
}
return j;
}
int main()
{
char a[M], ch;
cout << "\nPlease enter a string:";
gets_s(a);
cout << "\nPlease enter a char:";
ch = getchar();
cout << "\nThe number of the char is: " << fun(a, ch) << endl;
}
请编写函数fun,求出ss所指字符串指定字符的个数,并返回此值。
最新推荐文章于 2023-06-05 21:08:18 发布