当前位置: C语言 -- 标准库 -- <string.h> -- strcat

strcat函数


概要:
#include <string.h>
char *strcat(char * restrict s1, 
      const char * restrict s2);

描述:

该函数将参数s2指向字符串(包括终止空字符。)添加到参数s1指向字符串的末尾。参数s2指向字符串的初始字符覆盖参数s1指向字符串的终止空字符。

参数s1指向的数组应足够大,能够容纳生成的结果字符串。

如果复制发生在重叠对象之间,函数行为是未定义的。

ISO/IEC 9899:2018标准定义了该函数的安全版本strcat_s


参数:
char * restrict s1

指向目标数组的指针,结果字符串将存入该数组。

const char * restrict s2

指向连接字符串的指针。


返回值:

函数返回s1的值。


范例:
1 
2 
3 
4 
5 
6 
7 
8 
9 
10 
11 
12 
13 
14 
15 
16 
/*函数strcat范例*/

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

int main(void)
{
    char strOne[12] = "Hello ";
    const char strTwo[] = "world";

    strcat(strOne, strTwo);
    puts(strOne);
    
    return 0;
}


输出:

Hello world


相关内容:
strncat 向字符串添加限定数量字符的函数。