mmeemmccppyy() -- String Function (libc)

Copy one region of memory into another
#iinncclluuddee <ssttrriinngg.hh>
cchhaarr *mmeemmccppyy(_r_e_g_i_o_n_1, _r_e_g_i_o_n_2, _n)
vvaaddddrr_tt _r_e_g_i_o_n_1;
vvaaddddrr_tt _r_e_g_i_o_n_2;
uunnssiiggnneedd iinntt _n;

mmeemmccppyy() copies _n characters from _r_e_g_i_o_n_2 into _r_e_g_i_o_n_1. Unlike the routines
ssttrrccppyy()  and  ssttrrnnccppyy(),  mmeemmccppyy()  copies  from  one region  to  another.
Therefore, it will not halt automatically when it encounters NUL.

mmeemmccppyy() returns _r_e_g_i_o_n_1.

_E_x_a_m_p_l_e
The following example copies a structure and displays it.

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

struct stuff {
    int a, b, c;
} x, y;

main()
{
    x.a = 1;
    /* this would stop strcpy or strncpy. */
    x.b = 0;
    x.c = 3;

    /* y = x; would do the same */
    memcpy(&y, &x, sizeof(y));
    printf("a =%d, b =%d, c =%d\n", y.a, y.b, y.c);
    return(EXIT_SUCCESS);
}

_S_e_e _A_l_s_o
lliibbcc, ssttrrccppyy(), ssttrriinngg.hh
ANSI Standard, section 7.11.2.1

_N_o_t_e_s
If  _r_e_g_i_o_n_1 and  _r_e_g_i_o_n_2 overlap,  the behavior  of mmeemmccppyy()  is undefined.
_r_e_g_i_o_n_1 should  point to enough  reserved memory to  hold _n bytes  of data;
otherwise, code or data will be overwritten.
