-->
当前位置:首页 > 题库

函数题:字符串拼接 - C/C++ 指针及引用

Luz4年前 (2022-09-06)题库512
函数strAppend(d,s)将以0结尾的字符串s附加到以0结尾的字符串d之后。请实现该函数,使得后续程序可以正确运行。请注意为目标字符串分配足够的内存空间,以免溢出。注意不能使用原生的strcat()函数。

示例:指针d所指向的字符串"hello"在附加字符串"world"后变为"helloworld"。


### 函数接口定义:
c++
void strAppend(char *d, const char* s);



### 裁判测试程序样例:
c++
#include <stdio.h>

//在此处定义strAppend()函数

int main()
{
char s1[1024];
char s2[1024];

gets(s1);
gets(s2);
strAppend(s1,s2);
printf("%s",s1);
return 0;
}


### 输入样例:
in
hello
world


### 输出样例:
out
helloworld


请注意:函数题只需要提交相关函数的定义代码,不要提交完整程序。


### 感觉不会?  那试着听听**免费的B站网课**
[简洁的C和C++ - 重庆大学在线课程](https://www.bilibili.com/video/BV1it411d7zx/)
[Python编程基础及应用 - 重庆大学在线课程](https://www.bilibili.com/video/BV1kt411R7uW/)
![image.png](~/6e79c9e3-cb7f-486d-ab78-36b5a8f655c0.png)







答案:若无答案欢迎评论