时间:2012-04-06 22:06:15
第十一套
1程序填空
给定程序中,函数fun的功能是将带头结点的单向链表逆置。即若原链表中从头至尾结点数据域依次为:2、4、6、8、10,逆置后,从头至尾结点数据域依次为:10、8、6、4、2、。
第1处 p=h->next;
第2处 if (p==0) return;
第3处 p=q; q=r;
2程序修改
给定MODI1.Cfun函数的功能是:计算s所指字符串中含有t所指字符串的数目,并作为函数值返回。请改正函数fun中指定部位的错误,使它能得出正确的结果。
# include <stdio.h>
# include <string.h
#define N 80
int fun(char *s, char *t)
{int n;
char *p,*r;
n=0;
while (*s)
{ p=s;
/*******found******/
r=t;
while (*r)
if(*r==*p){r++;p++;}
else break;
/*******found******/
if(*r==0)
n++;
s++;
}
return n;
}
3程序设计
请编写函数fun,函数的功能是:将放在字符串数组中的M个字符串(每串的长度不超过N),按顺序合并组成一个新的字符串,函数fun中给出的语句供供参考。
void fun (char a[M][N]),char *b)
{int I;*b=0;
for(i=0;i<M;i++)strcat(b,a[i]);
}