C Standard Library

C <wchar.h> - wmemset() Function



The C <wchar.h> wmemset() function copies the wide character wc into each of the first num wide characters of the wide character array pointed to by ptr.

The behavior is undefined if num is greater than the size of the wide character array pointed to by ptr.

Syntax

wchar_t* wmemset (wchar_t* ptr, wchar_t wc, size_t num);

Parameters

ptr Specify pointer to the wide character array to fill.
value Specify the fill wide character.
num Specify the number of wide characters to fill.
size_t is an unsigned integer type.

Return Value

Returns ptr.

Example:

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

#include <stdio.h>
#include <wchar.h>
 
int main (){
  wchar_t str[50] = L"Hello World!";

  //displaying str
  printf("str is: %ls\n", str);

  //setting first 5 wide characters of str to $ 
  wmemset(str, '$', 5);

  //displaying str
  printf("str is: %ls\n", str);
  
  return 0;
}

The output of the above code will be:

str is: Hello World!
str is: $$$$$ World!

❮ C <wchar.h> Library