代码点读机 / C / strcat

strcat C · 字符串函数

把源字符串拼接到目标字符串末尾,目标数组必须有足够空间。

怎么用

strcat(目标数组, 源字符串);

小例子

#include <stdio.h>
#include <string.h>
int main(void) {
    char a[20] = "Hello";
    strcat(a, " World");
    printf("%s", a);
    return 0;
}

运行结果

输出 Hello World

提醒:目标数组要装得下两个字符串加结尾 \0;strncat 可限制最大追加长度

官方文档:https://en.cppreference.com/w/c/string/byte/strcat

在代码里遇到不认识的词?打开代码点读机,点一下就懂 → ← C全部词条