扫描二维码下载沐宇APP

沐宇

微信扫码使用沐宇小程序

沐宇

c语言如何把字符串连接

扬州沐宇科技
2023-08-15 02:34:14
c语言

在C语言中,可以使用strcat函数将两个字符串连接起来。

strcat函数的原型如下:

char* strcat(char* destination, const char* source);

其中,destination是目标字符串,source是要连接的字符串。

使用strcat函数的示例代码如下:

#include <stdio.h>
#include <string.h>
int main() {
char str1[50] = "Hello";
char str2[] = " World!";
strcat(str1, str2);
printf("Concatenated string: %s\n", str1);
return 0;
}

输出结果:

Concatenated string: Hello World!

以上代码将字符串"Hello"和" World!"连接起来,结果存储在str1中。

扫码添加客服微信