可以使用字符串拼接函数strcat()来连接两个字符串。strcat()函数的原型为:

char *strcat(char *dest, const char *src);

其中,dest是目标字符串,src是要添加到目标字符串的源字符串。函数将源字符串添加到目标字符串的末尾,并返回目标字符串的地址。

以下是一个示例程序,演示如何使用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;
}

输出结果为:

Concatenated string: Hello world!
C语言字符串连接:使用strcat()函数

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

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