以下是用 C 语言合并两个字符串的示例代码:

#include <stdio.h>
#include <string.h>

int main() {
    char str1[50], str2[50];
    printf('请输入第一个字符串:');
    scanf('%s', str1);
    printf('请输入第二个字符串:');
    scanf('%s', str2);

    strcat(str1, str2); // 合并字符串
    printf('合并后的字符串为:%s\n', str1);

    return 0;
}

在上面的例子中,我们使用了 C 语言中的 strcat() 函数来合并两个字符串。strcat() 函数可以将第二个字符串追加到第一个字符串的末尾,从而实现字符串的合并。需要注意的是,在使用 strcat() 函数之前,第一个字符串必须是足够大的字符数组,以容纳合并后的字符串。

C语言字符串合并:使用 strcat() 函数示例

原文地址: https://www.cveoy.top/t/topic/mM0W 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录