改错题 下列给定程序中,函数fun的功能是:计算s所指字符串含有t所指字符串的数目,,并作为函数的值返回。
请改正函数fun 中的错误或在横线处填上适当的内容并把横线删除,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!
试题程序:
#include <conio.h>
#include <stdio.h>
#include <string.h>
#define N 80
int fun(char *s, char *t)
{
int n;
char *p, *r;
n = 0;
/********found********/
p = &s[0];
*r = t;
while (*p)
{
if (*r == *p)
{
r++;
if (*r == '\0')
{
n++;
/********found********/
___ì???___
}
}
p++;
}
return n;
}
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);
m = printf("\nThe result is:m=%d\n", m);
}
第1处:*r=t;应改为r=t;或r=&t[0];
第2处:应填r=t;或r=&t[0];