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"
*/