填空题

下列给定程序中,函数fun()的功能是:计算s所指字符串中含有t所指字符串的数目,并作为函数值返回。 请改正程序中的错误,使它能得出正确的结果。 注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。 试题程序: #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; while(*s) { p=s; /**************found***************/ r=p; while(*r) if{*r==*p) {r++; p++;} else break; /**************found***************/ if(*r==0) n++; s++; } return n; } main() {char a[N],b[N]; int m; clrscr(); 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); }

【参考答案】

错误:r=p; 正确;r=t;