Linux 拨号vps windows公众号手机端

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

lewis 9年前 (2016-11-07) 阅读数 7 #程序编程
文章标签 c语言

在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!"

版权声明

本文仅代表作者观点,不代表米安网络立场。

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

热门