问答题
下列给定程序中,函数fun的功能是:计算s所指字符串中含有t所指字符串的数目,并作为函数值返回。
请改正程序中的错误或在下画线处填上正确的内容并把下画线删除,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!
试题程序:
#include<stdlib.h>
#include<conio.h>
#include<string.h>
#include<stdio.h>
#define N 80
int fun(char*s,char*t)
{ int n;
char*P,*r;
n=0 ;
/*********found*********/
*r=t;
while(*S)
{
p=s ;
while(*r)
{
if(*r==*P)
{
r++;
p++;
}
else
break;
if(*r==’\0’)
n++;
}
/*********found*********/
1
;
s++;
}
return n;
}
void main()
{char a[N],b[N];int m;
printf("\nPlease enter string a:");
gets(a);
printf("\nPlease enter substring b:");
gets(b);
m=fun(a,b);
printf("\nThe result is:m=%d\n",m);
}
【参考答案】
正确答案:(1)r=t; (2)r=t;或r=&t[0];