Desc :

void* memcpy( void* dest, const void* src, unsigned int count );

dest - 복사될 버퍼

src - 복사할 버퍼

count - 복사할 src의 메모리 크기

 

구조체, 배열 등을 일일이 복사하지 않고 한번에

 

strcpy --> 문자열을 복사하는 함수, null까지만 복사

memcpy --> null 값이 있는 경우에도 지정된 길이만큼 모두 복사

 


Source Code :

#include <stdio.h>
#include <string.h>

struct tagM1
{
	int x;
	int y;
	char buffer[30];
};

void main()
{
	struct tagM1 x1, x2;

	x1.x = 5;
	x1.y = 10;
	strcpy(x1.buffer, "memory copy");	// 구조체 초기화

	memcpy(&x2, &x1, sizeof(x1));

	puts(x2.buffer);
}

 


Result :

 

 

+ Recent posts