题目内容:
下列给定程序中,函数proc()的功能是:将m(1≤m≤10)个字符串反着连接起来,组成一个新串,放入pt所指字符串中,例如,把“ab、cd、efg”3个字符串反着串联起来,结果是efgcdab。 请修改程序中的错误,使它能得出正确的结果。
注意:不要改动main()函数,不得增行或者删行,也不得改变程序的结构!
试题程序:
#include<stdlib.h>
#include<conio.h>
#include<string.h>
#include<stdio.h>
void proc(char str[][10],int m,char*pt)
{
int k,q,i,j=0;
//****found****
for(k=m;k>0;k--)
{
q=strlen(str[-k]);
j+=q;
for(i=0;i<q;i++)
pt[i]=strl-k][i];
pt+=q;
pt[0]=0:
}
//****found****
pt=j;
}
void main()
{
int m,h;
char str[10][10],p[120];
system("CLS"):
printf("\nPlease enter m:");
scanf("%d",&m);
printf("\nPlease enter%d strin9:\n",m);
gets(str[0]);
for(h=0;h<m;h++)
gets(str[h]);
proc(str,m,p);
printf("\nThe result is:%s\n",p);
}
参考答案:
答案解析: