C 庫函數 - strcat()

C 標準庫 - <string.h> C 標準庫 - <string.h>

描述

C 庫函數 char *strcat(char *dest, const char *src)src 所指向的字串追加到 dest 所指向的字串的結尾。

聲明

下麵是 strcat() 函數的聲明。

char *strcat(char *dest, const char *src)

參數

  • dest -- 指向目標數組,該數組包含了一個 C 字串,且足夠容納追加後的字串。
  • src -- 指向要追加的字串,該字串不會覆蓋目標字串。

返回值

該函數返回一個指向最終的目標字串 dest 的指針。

實例

下麵的實例演示了 strcat() 函數的用法。

實例

#include <stdio.h> #include <string.h> int main () { char src[50], dest[50]; strcpy(src, "This is source"); strcpy(dest, "This is destination"); strcat(dest, src); printf("最終的目標字串: |%s|", dest); return(0); }

讓我們編譯並運行上面的程式,這將產生以下結果:

最終的目標字串: |This is destinationThis is source|

C 標準庫 - <string.h> C 標準庫 - <string.h>