改错题 下列给定程序中,函数fun的功能是,将s所指字符串的正序和反序进行连接,形成一个新串放在t所指的数组中,例如,当s所指这字符串为ABCD时,则t所指字符串中的内容应为ABCDDCBA。
请改正程序中的错误,使其能得出正确结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!
试题 程序:
#include <conio.h>
#include <stdio.h>
#include <string.h>
/********found********/
void fun(char s, char t)
{
int i, d;
d = strlen(s);
for (i=0; i<d; i++)
t[i] = s[i];
for (i=0; i<d; i++)
t[d+i] = s[d-1-i];
/********found********/
t[2*d-1] = '\0';
}
main()
{
char s[100], t[100];
printf("\nPlease enter string S:");
scanf("%s", s);
fun(s, t);
printf("\nThe result is : %s\n", t);
}
第1处:void fun(char s,char t)应改为void fun(char *s;char *t)
第2处:t[2*d-1]=’\0’;应改为t[2*d]=’\0’;或t[d+i]=’\0’;或t[2*d]=0;或t[d+i]=0;