以下试题来自:
问答题编写一个函数,用该函数可以统计一个长度为3的字符串在另一个字符串中出现的次数。例如,假定输入字符串“the abcthe they have theren”,子字符串为“the”,则应输出4。
注意:部分源程序在文件PROC2.CPP中。
请勿改动主函数和其他函数中的任何内容,仅在fun()的花括号中填入编写的若干语句。
部分源程序如下:
//PROC2.CPP
#include <iostream>
#define MAX 100
int fun(char *str,char *substr);
int main()
char str[MAX],substr[3];
cout<<"Please Input the source String\n";
cout<<"Please Input the subString\n";
n=fun(str, substr);
cout<<"The counter is: "<<n<<end1;
int fun(char *str,char *substr)
//****** int fun(char *str,char *substr){int n,z;n=0;for (z=0;str [z] !=&\0&;z++){