strcat ()- 連結字串

格式

#include <string.h>
char *strcat(char *string1, const char *string2);

語言層次

ANSI

安全執行緒

說明

strcat() 函數會將 string2 連結至 string1 ,並以空值字元結束產生的字串。

strcat() 函數會對以空值結尾的字串進行操作。 函數的字串引數應該包含標示字串結尾的空值字元 (\0)。 不執行長度檢查。 雖然 string2 可能是文字字串,但您不應該對 string1 值使用文字字串。

如果 string1 的儲存體與 string2的儲存體重疊,則行為未定義。

回覆值

strcat() 函數會傳回連結字串 (string1) 的指標。

範例

此範例會使用 strcat()來建立字串 "computer program"
#include <stdio.h>
#include <string.h>
 
#define SIZE 40
 
 
int main(void)
{
  char buffer1[SIZE] = "computer";
  char * ptr;
 
  ptr = strcat( buffer1, " program" );
  printf( "buffer1 = %s\n", buffer1 );
 
}
 
/*****************  Output should be similar to:  *****************
 
buffer1 = computer program
*/

相關資訊