C 庫函數 - strcat()

C 庫函數 - strcat()

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|
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章