填空题
请补充函数proc(),该函数可以统计一个长度为n的字符串在另一个字符串中出现的次数。例如,假定输入的字符串为:fjdkad**fdadf fdadjkfdad,子字符串为ad,则应输出4。
注意:部分源程序给出如下。
请勿改动main()函数和其他函数中的任何内容,仅在函数proc()的横线上填入所编写的若干表达式或语句。
试题程序:
#include<stdlib.h>
#include<stdio.h>
#include<string.h>
#include<conio.h>
int proc(char*str.char*sub)
{
int n;
char*p,*r;
n=0;
while(*str)
{
p=str;
r=sub;
while(
1)
if(*r==*p)
{
r++;
p++;
}
else
2;
if(*r=="/0")
n++;
sir++;
}
return
3;
}
void main()
{
char str[81],suh[3];
int n;
system("CLS");
printf("输入主字符串:");
gets(str);
printf("输入子字符串:");
gets(sub);
puts(str);
puts(sub);
n=proc(str,sub);
printf("n=%d/n",n);
}