问题 多项选择题

下列给定程序中,函数fun的功能是:将s所指字符串的正序和反序进行连接,形成的新串放在t所指的数组中。
请改正程序中的错误,使它能得出正确的结果。
注意:不要改动mam函数,不得增行或删行,也不得更改程序的结构!
试题程序:
#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);

答案

参考答案:(A) void fun(char*s, char *t)
(B)t[B*d]=’\0’; 或t[d+i]=’\0’; 或t[B*d]=0; 或t[d+i]=0;

解析: (1)主函数中调用语句中实参为数组,所以形参应为指针。
(2)字符串连接后字符的个数为2*d个,数组下标从0开始,最后一个字符的下标为2*d-1,所以结束符’\0’下标为2*d。

单项选择题
单项选择题 A1型题