|
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Defined in header <wchar.h> | ||
| (1) | ||
wchar_t* wmemcpy(wchar_t* dest,constwchar_t* src,size_t count); | (since C95) (until C99) | |
wchar_t*wmemcpy(wchar_t*restrict dest,constwchar_t*restrict src, size_t count); | (since C99) | |
errno_t wmemcpy_s(wchar_t*restrict dest, rsize_t destsz, constwchar_t*restrict src, rsize_t count); | (2) | (since C11) |
count successive wide characters from the wide character array pointed to bysrc to the wide character array pointed to bydest. If the objects overlap, the behavior is undefined. Ifcount is zero, the function does nothing.src ordest is a null pointerdestsz orcount is greater thanRSIZE_MAX/sizeof(wchar_t)count is greater thandestsz (overflow would occur)wmemcpy_s is only guaranteed to be available if__STDC_LIB_EXT1__ is defined by the implementation and if the user defines__STDC_WANT_LIB_EXT1__ to the integer constant1 before including<wchar.h>.Contents |
| dest | - | pointer to the wide character array to copy to |
| src | - | pointer to the wide character array to copy from |
| count | - | number of wide characters to copy |
| destsz | - | max number of wide characters to write (the size of the destination buffer) |
destdst up to and not includingdst+dstsz with null wide characters,L'\0' (unlessdest is null ordestsz is greater thanRSIZE_MAX/sizeof(wchar_t))This function's analog for byte strings isstrncpy, notstrcpy.
This function is not locale-sensitive and pays no attention to the values of thewchar_t objects it copies: nulls as well as invalid characters are copied too.
#include <stdio.h>#include <wchar.h>#include <locale.h> int main(void){wchar_t from1[]= L"नमस्ते";size_t sz1=sizeof from1/sizeof*from1;wchar_t from2[]= L"Բարև";size_t sz2=sizeof from2/sizeof*from2;wchar_t to[sz1+ sz2]; wmemcpy(to, from1, sz1);// copy from1, along with its null terminator wmemcpy(to+ sz1, from2, sz2);// append from2, along with its null terminator setlocale(LC_ALL,"en_US.utf8");printf("Wide array contains: ");for(size_t n=0; n<sizeof to/sizeof*to;++n)if(to[n])printf("%lc", to[n]);elseprintf("\\0");printf("\n");}
Possible output:
Wide array contains: नमस्ते\0Բարև\0
(C95)(C11) | copies a certain amount of wide characters between two, possibly overlapping, arrays (function)[edit] |
(C11) | copies a certain amount of characters from one string to another (function)[edit] |
C++ documentation forwmemcpy | |