.TH memcpy() "" "" "String Function (libc)"
.PC "Copy one region of memory into another"
.B "#include <string.h>"
\fBchar *memcpy(\fIregion1\^\fB, \fIregion2\^\fB, \fIn\^\fB)\fR
\fBvaddr_t \fIregion1\^\fB;\fR
\fBvaddr_t \fIregion2\^\fB;\fR
\fBunsigned int \fIn\^\fB;\fR
.PP
.II "character, copy"
.II "region of memory, copy"
.II "memory, copy"
.II "copy a region of memory"
.B memcpy()
copies
.I n
characters from
.I region2
into
.IR region1 .
Unlike the routines
.B strcpy()
and
.BR strncpy() ,
.B memcpy()
copies from one region to another.
Therefore, it will not halt automatically when it encounters NUL.
.PP
.B memcpy()
returns
.IR region1 .
.SH Example
The following example copies a structure and displays it.
.DM
#include <string.h>
#include <stdio.h>
.DE
.DM
struct stuff {
	int a, b, c;
} x, y;
.DE
.DM
main()
{
	x.a = 1;
	/* this would stop strcpy or strncpy. */
	x.b = 0;
	x.c = 3;
.DE
.DM
	/* y = x; would do the same */
	memcpy(&y, &x, sizeof(y));
	printf("a =%d, b =%d, c =%d\en", y.a, y.b, y.c);
	return(EXIT_SUCCESS);
}
.DE
.SH "See Also"
.Xr "libc," libc
.Xr "strcpy()," strcpy
.Xr "string.h" string.h
.br
\*(AS, \(sc7.11.2.1
.SH Notes
If
.I region1
and
.I region2
overlap, the behavior of
.B memcpy()
is undefined.
.I region1
should point to enough reserved memory to hold
.I n
bytes of data; otherwise, code or data will be overwritten.
