在C语言中,可以使用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;
}
上述代码中,首先定义了两个字符串数组str1
和str2
,然后使用strcat()
函数将str2
连接到str1
的末尾,最终输出连接后的字符串。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读:c语言如何把两个字符串连接起来