memcpy() — 바이트 복사

형식

#include <string.h>
void *memcpy(void *dest, const void *src, size_t count);

언어 레벨

ANSI

스레드세이프  

설명

memcpy() 함수는 srccount 바이트를 dest로 복사합니다. 복사가 중첩되는 오브젝트 사이에 발생되면 작동이 정의되지 않습니다. memmove() 함수를 사용하면 겹칠 수 있는 오브젝트 간에 복사할 수 있습니다.

리턴값

memcpy() 함수는 dest에 대한 포인터를 리턴합니다.

이 예는 소스의 컨텐츠를 대상에 복사합니다.
#include <string.h>
#include <stdio.h>
 
#define MAX_LEN 80
 
char source[ MAX_LEN ] = "This is the source string";
char target[ MAX_LEN ] = "This is the target string";
 
int main(void)
{
  printf( "Before memcpy, target is \"%s\"\n", target );
  memcpy( target, source, sizeof(source));
  printf( "After memcpy, target becomes \"%s\"\n", target );
}
 
/*********************  Expected output:  ************************
 
Before memcpy, target is "This is the target string"
After memcpy, target becomes "This is the source string"
*/

관련 정보