cplusplus.com > reference > cstring > memcpy
memcpy
<string.h>
  cplusplus.com  
void *  memcpy ( void * dest, const void * src, size_t num );

Copy bytes to buffer from buffer.
  Copies num bytes from src buffer to memory location pointed by dest.

Parameters.

dest
Destination buffer where data is copied.
src
Source buffer to copy from.
num
Number of bytes to copy.

Return Value.
  dest is returned.

Portability.
  Defined in ANSI-C.

Example.

/* memcpy example */
#include <stdio.h>
#include <string.h>

int main ()
{
  char str1[]="Sample string";
  char str2[40];
  char str3[40];
  memcpy (str2,str1,strlen(str1)+1);
  memcpy (str3,"copy successful",16);
  printf ("str1: %s\nstr2: %s\nstr3: %s\n",str1,str2,str3);
  return 0;
}
Output:
str1: Sample string
str2: Sample string
str3: copy successful

See also.
  memchr, memcmp, memset, strncpy


© The C++ Resources Network, 2000