温馨提示×

c语言如何把字符串连起来

小亿
123
2024-03-22 18:47:41
栏目: 编程语言

在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的末尾,最终输出结果为"Hello, world!"

0