C语言字符串连接:使用strcat函数
可以使用strcat函数实现连接两个字符串。
例如,将字符串str1和str2连接起来:
#include <stdio.h>
#include <string.h>
int main() {
char str1[20] = "hello";
char str2[20] = "world";
strcat(str1, str2);
printf("str1: %s", str1);
return 0;
}
输出:
str1: helloworld
注意,使用strcat函数时,要确保目标字符串(即第一个参数)有足够的空间来存储连接后的字符串。
原文地址: https://www.cveoy.top/t/topic/mZfV 著作权归作者所有。请勿转载和采集!