首页 > 编程知识 正文

实现strcat函数,不用strcat函数连接字符串

时间:2023-05-04 06:25:35 阅读:255477 作者:227

strcat是STRing CATenate(字符串连接)的缩写,调用strcat函数首先要有<string.h>这个头文件,它的作用是把两个字符数组中的字符串连接起来,把字符串2连接到字符串1的后面。
注意:
1.字符数组1必须足够大;
2.连接时将字符串1后面的’’取消,只在新字符串最后保留’’;
3.直接strcat(str1,str2)就行,不用新定义数组存放;
举个例子:
Sample Input
cai niao
Sample Output
I am cai niao, I can make it!
代码如下:

#include<stdio.h>#include<string.h>int main(){char x[1000];gets(x);char a[1000]={"I am "};char b[1000]={",I can make it!"};strcat(a,x);strcat(a,b); printf("%s",a);return 0;}

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。