C 庫函數(shù) - strcat()

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

描述

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

聲明

下面是 strcat() 函數(shù)的聲明。

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

參數(shù)

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

返回值

該函數(shù)返回一個指向最終的目標字符串 dest 的指針。

實例

下面的實例演示了 strcat() 函數(shù)的用法。

#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);
}

讓我們編譯并運行上面的程序,這將產(chǎn)生以下結果:

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

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