C语言教程-C字符串拼接:strcat()函数
strcat(first_string, second_string)函数用于将两个字符串拼接在一起,并将结果返回给第一个字符串。
#include <stdio.h>
#include <string.h>
int main() {
char ch[10] = {'h', 'e', 'l', 'l', 'o', '\0'};
char ch2[10] = {'c', '\0'};
strcat(ch, ch2);
printf("第一个字符串的值为:%s", ch);
return 0;
}输出:
第一个字符串的值为:helloc在上面的示例中,使用strcat()函数将字符串ch2拼接到字符串ch的末尾。然后使用printf()打印第一个字符串的值。