C 庫函數 - strncat()
描述
C 庫函數 char *strncat(char *dest, const char *src, size_t n) 把 src 所指向的字串追加到 dest 所指向的字串的結尾,直到 n 字元長度為止。
聲明
下麵是 strncat() 函數的聲明。
char *strncat(char *dest, const char *src, size_t n)
參數
- dest -- 指向目標數組,該數組包含了一個 C 字串,且足夠容納追加後的字串,包括額外的空字元。
 - src -- 要追加的字串。
 - n -- 要追加的最大字符數。
 
返回值
該函數返回一個指向最終的目標字串 dest 的指針。
實例
下麵的實例演示了 strncat() 函數的用法。
#include <stdio.h>
#include <string.h>
int main ()
{
   char src[50], dest[50];
   strcpy(src,  "This is source");
   strcpy(dest, "This is destination");
   strncat(dest, src, 15);
   printf("最終的目標字串: |%s|", dest);
   return(0);
}
讓我們編譯並運行上面的程式,這將產生以下結果:
最終的目標字串: |This is destinationThis is source|

 C 標準庫 - <string.h>