The wmemset()
function in C copies a single wide character for a specified number of times to a wide-character array.
Wide characters are similar to character datatype. The main difference between the two is that char takes 1-byte
space, while the wide-character takes 2-bytes
of space in memory (sometimes 4-byte
, depending on compiler).
For 2-byte space, wide characters can hold 64K (65536)
different characters. The wide char can hold UNICODE
characters.
#include <cwchar>
wchar_t* wmemset( wchar_t* destination, wchar_t ch, size_t count );
The wmemset()
function takes three arguments:
destination
ch
count
The wide-character represented by ch
is copied into the first count characters of the wide-character array pointed to by dest.
destination
: Pointer to the wide-character array to copy the wide-character.
ch
: The wide character to copy
count
: Number of times to copy
#include <cwchar>#include <clocale>#include <iostream>using namespace std;int main(){wchar_t ch = 'B'; //Inputwchar_t dest[20]; //Array to Store Dataint count = 5; //defines how many times you have to iteratewmemset(dest, ch, count); //pass variables to functionwcout << "After copying " << ch << " 5 times" << endl;for(int i = 0; i < count; i++)putwchar(dest[i]); //store the data in arrayreturn 0;}