c语言如何拼接字符串

   2024-10-15 8540
核心提示:在C语言中,可以使用strcat()函数来拼接字符串。下面是一个示例:#include stdio.h#include string.hint main() {char str1[50]

在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;}

上面的代码首先定义了两个字符串str1str2,然后使用strcat()函数将str2连接到str1的末尾,最终输出拼接后的字符串。

 
举报打赏
 
更多>同类维修大全
推荐图文
推荐维修大全
点击排行

网站首页  |  关于我们  |  联系方式网站留言    |  赣ICP备2021007278号