填空题 1.  下列给定程序中,函数fun的功能是:先将s所指字符串中的字符按逆序存放到t所指字符串中,然后把s所指串中的字符按正序连接到t所指串之后。
    例如,当s所指的字符串为“ABCDE”时,t所指的字符串应为“EDCBAABCDE”。
    请改正程序中的错误,使它能得出正确的结果。
    注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!
    试题程序:
    #include<stdlib.h>
    #include<conio.h>
    #include<stdio.h>
    #include<string.h>
    void fun(char *s, char *t)
    {
    /*********found*********/
    int i;
    s1=strlen(s);
    for(i=0; i<s1; i++)
    /*********found*********/
    t[i]=s[s1-i];
    for(i=0;i<=s1; i++)
    t[s1+i]=s[i];
    t[2 *s1]='\0';
    }
    void main()
    {
    char s[100], t[100];
    system("CLS");
    printf("\n Please enter string s:");
    scanf("%s",s);
    fun(s,t);
    printf("The result is:% s\n",t);
    }
  • 1、
【正确答案】 1、(1)int i, sl;
   (2)t[i]=s[sl-i-1];    
【答案解析】
   (1)变量sl没有定义。
   (2)该循环实现将s串中的字符逆序存入t串中,t[i]对应s串中的s[sl-i-1]。