问答题
下列给定程序中,函数proc()的功能是:计算str所指字符串中含有t所指字符串的数目,并作为函数值返回。
请修改程序中的错误,使它能得出正确的结果。
注意:不要改动main()函数,不得增行或删行,也不得更改程序的结构。
试题程序:
#include<stdlib.h>
#include<conio.h>
#include<string.h>
#include<stdio.h>
#define M 80
int proc(char *str, char *t)
{
int n;
char *p, *r;
n=0;
while(*str)
{
p=str;
//****found****
r=p;
while(*r)
if(*r==*p){r++; p++; }
else break;
//****found****
if(*r==0)
n++;
str++;
}
return n;
}
void main()
{
char str[M], b[M]; int m;
system("CLS");
printf("/nPlease enter string str:");
gets(str);
printf("/nPlease enter substring b:");
gets(b);
m=proc(str, b);
printf("/nThe result is:m=%d/n", m);
}