下列给定程序中,函数fun的功能是:先将s所指字符串中的字符按逆序存放到t所指字符串中,然后把s所指串中的字符按正序连接到t所指串之后。 例如,当s所指的字符串为“ABCDE”时,t所指的字符串应为“EDCBAABCDE”。 请改正程序中的

admin2017-09-23  19

问题 下列给定程序中,函数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=str1en(s);
    for(i=0;i < s1;i++)
/*********found*********/
    t=s[s1一i];
    for(i=0 ; i < =s1 ; i++)
    t[s1+i]=s
    t[2*s1]=’\0’;
}
void main()
{
  char s[1 00],t[1 00];
  system("CLS");
  printf("\n Please enter
string s:");
    scanf("%s",s);
    fun(S,t);
    printf ("The result is:%s\n",t);
}

选项

答案(1)int i,s1; (2)t[i] =s[s1一i一1];

解析 (1)变量s1没有定义。
(2)该循环实现将s串中的字符逆序存入t串中,t对应s串中的s[s1一i一1]。
转载请注明原文地址:https://kaotiyun.com/show/yoxp777K
0

最新回复(0)