strcpy ()- 複製字串
格式
#include <string.h>
char *strcpy(char *string1, const char *string2);語言層次
ANSI
安全執行緒
是
說明
strcpy() 函數會將 string2(包括結尾空值字元) 複製到 string1指定的位置。
strcpy() 函數會對以空值結尾的字串進行操作。 函數的字串引數應該包含標示字串結尾的空值字元 (\0)。 不執行長度檢查。 雖然 string2 可能是文字字串,但您不應該對 string1 值使用文字字串。
回覆值
strcpy() 函數會傳回複製字串 (string1) 的指標。
範例
此範例會將 source 的內容複製到 destination。
#include <stdio.h>
#include <string.h>
#define SIZE 40
int main(void)
{
char source[SIZE] = "This is the source string";
char destination[SIZE] = "And this is the destination string";
char * return_string;
printf( "destination is originally = \"%s\"\n", destination );
return_string = strcpy( destination, source );
printf( "After strcpy, destination becomes \"%s\"\n", destination );
}
/***************** Output should be similar to: *****************
destination is originally = "And this is the destination string"
After strcpy, destination becomes "This is the source string"
*/