function
<cwchar>

wmemcpy

wchar_t* wmemcpy (wchar_t* destination, const wchar_t* source, size_t num);
Copy block of wide characters
Copies the values of num elements of type wchar_t from the location pointed by source to the location pointed by destination.

The function does not check for any terminating null wide character in source - it always copies exactly num elements of type wchar_t.

To avoid overflows, the size of the arrays pointed by both the destination and source parameters, shall at least be num elements of type wchar_t, and should not overlap (for overlapping memory blocks, wmemmove is a safer approach).

This is the wide character equivalent of memcpy (<cstring>).

Parameters

destination
Pointer to the destination array where the content is to be copied.
source
Pointer to the source of data to be copied.
num
Number of bytes to copy.
size_t is an unsigned integral type.

Return Value

destination is returned.

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
/* wmemcpy example */
#include <wchar.h>

int main ()
{
  wchar_t wcs1[] = L"To be or not to be";
  wchar_t wcs2[40];
  wchar_t wcs3[40];

  wcsncpy ( wcs2, wcs1, 40 );  /* copies 19 characters, then fills with L'\0' */
  wmemcpy ( wcs3, wcs1, 40 );  /* copies 40 characters */

  wprintf (L"%ls\n%ls\n%ls\n",wcs1,wcs2,wcs3);

  return 0;
}

Output:
To be or not to be
To be or not to be
To be or not to be


See also