函式
<cstring>

strncat

char * strncat ( char * destination, const char * source, size_t num );
從字串追加字元
source 的前 num 個字元追加到 destination,並加上一個終止的空字元。

如果 source 中的 C 字串長度小於 num,則只複製到終止的空字元為止。

引數

destination
目標陣列的指標,該陣列應包含一個 C 字串,並且足夠大,可以包含連線後的結果字串,包括附加的空字元。
source
要追加的 C 字串。
num
要追加的最大字元數。
size_t 是一個無符號整數型別。

返回值

返回 destination

示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
/* 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


另見