strcat是STRing CATenate(字符串连接)的缩写,调用strcat函数首先要有<string.h>这个头文件,它的作用是把两个字符数组中的字符串连接起来,把字符串2连接到字符串1的后面。
注意:
1.字符数组1必须足够大;
2.连接时将字符串1后面的’\0’取消,只在新字符串最后保留’\0’;
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;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)