Home C&C++函数库 c++ 语法 程序源码 Linux C库

strncat

函数   <cstring>

char * strncat ( char * destination, const char * source, size_t num );

在字符串中追加字符

将源(source) 的开始的num个字符附加到目标 (destination),再加上一个结束的空字符。

如果source中的C字符串长度小于num,则只复制到结束空字符之前的内容。

☲  参数


destination
指向目标数组的指针,该数组应该包含一个C字符串,并且要足够大,以包含连接的结果字符串,包括额外的空字符。

source
要附加的C字符串。

num
附加的最大字符数。
Size_t是一个无符号整型。

☉  返回值



返回 destination 。

☣  示例



/* strncat example */
#include <stdio.h>
#include <string.h>

int main ()
{
  char str1[20];
  char str2[20];
  strcpy (str1,"To be ");
  strcpy (str2,"or not to be");
  strncat (str1, str2, 6);
  puts (str1);
  return 0;
}

输出:
To be or not

🍄  另请参阅



strcat 连接字符串(function)
strncpy 从字符串复制字符(function)
memcpy 拷贝内存块(function)

联系我们 免责声明 关于CandCplus 网站地图