Facebook Page Twitter Page LinkedIn Page
× C Standard Library


The C <wchar.h> wmemcpy() function is used to copy num wide characters of memory block pointed to by source to the memory block pointed to by destination. The behavior of the function is undefined if destination and source overlaps.

Syntax

wchar_t* wmemcpy (wchar_t* destination, const wchar_t* source, size_t num);

Parameters

destination Specify pointer to the first block of memory where the content is to be copied.
source Specify pointer to the second block of memory to copy from.
num Specify number of wide characters to copy.
size_t is an unsigned integer type.

Return Value

Returns destination

Example:

The below example shows the usage of wmemcpy() function.

#include <stdio.h>
#include <wchar.h>
 
int main (){
  wchar_t str[50] = L"Hello World!";
  wchar_t new_str[50];
  
  //copying 5 wide characters of memory 
  //blocks str into memory block new_str
  wmemcpy(new_str, str, 5);

  //null wide character manually 
  //added to new_str
  new_str[5] = L'\0';
  
  //displaying the result
  printf("new_str contains: %ls", new_str);

  return 0;
}

The output of the above code will be:

new_str contains: Hello

❮ C <wchar.h> Library