可以使用strcpy函数和strcat函数来连接两个字符串。例如,将字符串s1和字符串s2连接成一个新的字符串s3,可以使用以下代码:

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

int main() {
    char s1[] = 'hello';
    char s2[] = 'world';
    char s3[100];

    strcpy(s3, s1); // 复制字符串s1到s3
    strcat(s3, s2); // 连接字符串s2到s3

    printf('s3 is: %s\n', s3);

    return 0;
}

输出结果为:

s3 is: helloworld
C语言字符串连接:strcpy和strcat函数详解

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

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