将s所指字符串的正序和反序进行连接,形成一个新串放在t所指的数组中。
函数接口定义:
void fun (char *s, char *t);
其中s 和t都是用户传入的参数。函数将s所指字符串的正序和反序进行连接,形成一个新串放在t所指的数组中。
裁判测试程序样例:
#include <stdio.h>
void fun (char *s, char *t);
int main()
{ char s[100], t[100];
scanf("%s", s);
fun(s, t);
printf("The result is: %s\n", t);
return 0;
}
/* 请在这里填写答案 */
输入样例:
abcd
输出样例:
The result is: abcddcba
void fun (char *s, char *t)
{
int len = 0;
while(*s != '\0')
{
*t = *s;
s++;
t++;
len++;
}
s--;
while(len--)
{
*t = *s;
s--;
t++;
}
*t = '\0';
}
本文介绍了一个函数,该函数接收两个字符数组s和t作为参数,并将s指向的字符串正序与反序拼接后存入t指向的数组中。通过这种方式可以有效地创建一个包含原始字符串及其反转版本的新字符串。

4089

被折叠的 条评论
为什么被折叠?



