可以使用strcat()函数来拼接两个字符串,示例代码如下:

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

int main() {
    char str1[20] = "hello";
    char str2[20] = "world";
    strcat(str1, str2);
    printf("拼接后的字符串为:%s", str1);
    return 0;
}

输出结果为:

拼接后的字符串为:helloworld

在上面的代码中,我们先定义了两个字符串str1和str2,然后使用strcat()函数将str2拼接到str1的末尾,并将结果存储在str1中。最后使用printf()函数输出拼接后的字符串。

用c语言拼接两个字符串

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

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