What is wmemmove in C?

The wmemmove function is used to copy the contents of one wide string into another wide string. The function stops when the specified number of characters is copied. The wmemmove function is defined in the wchar.h header.

Parameters

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

The function takes three parameters.

In the above snippet of code, source and destination are pointers of type wchar_t* and num is of type size_t The wide characters are copied from source to destination until the num number of characters are copied.

Return value

The function returns the pointer to the modified destination wide string. Its type is wchar_t*.

Example 1

#include<stdio.h>
#include<wchar.h>
void main() {
// declaring and initializing wide strings
wchar_t str1[] = L"HELLO WORLD";
wchar_t str2[12] = L"";
wchar_t str3[12] = L"";
// calling the function
wmemmove(str2, str1, 5);
wmemmove(str3, str1, 11);
// using the wprintf function to print the wide strings
wprintf(L"str2: %ls\n\n", str2);
wprintf(L"str3: %ls\n\n", str3);
}

In the above snippet of code, we copy the contents from str1 into str2 with the limit of 5 characters and str3 with 11 characters.

Example 2

#include<stdio.h>
#include<wchar.h>
void main() {
// declaring and initializing wide strings
wchar_t str1[] = L"HELLO WORLD";
wchar_t str2[15] = L"";
wchar_t str3[15] = L"";
// calling the function
wmemmove(str3, str1, 20);
wmemmove(str2, str1, 15);
// using the wprintf function to print the wide strings
wprintf(L"str2: %ls\n\n", str2);
wprintf(L"str3: %ls\n\n", str3);
}

In the above snippet of code, we copy 20 characters from str1 into str3 and 15 characters from str1 into str2. In this example, line 12 might produce an error or give an unpredictable output because the number of characters being copied is more than the size of the str3. To avoid any errors, the num parameter should be less than or equal to the size of arrays.

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved