strcat() - C語言庫函數

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("Final destination string : |%s|", dest);

   return(0);
}

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

Final destination string : |This is destinationThis is source|

上一篇: memset() - C語言庫函數 下一篇: strncat() - C語言庫函數