Linux 拨号vps windows公众号手机端

c语言如何把字符串连接

lewis 7年前 (2018-11-25) 阅读数 8 #程序编程
文章标签 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中。

版权声明

本文仅代表作者观点,不代表米安网络立场。

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

热门