wcscpy, wcscpy_s

Header: <wchar.h>

  1. Copies the wide string pointed to by src (including the terminating null wide character) to wide character array pointed to by dest. The behavior is undefined if the dest array is not large enough. The behavior is undefined if the strings overlap.

# Declarations

wchar_t* wcscpy( wchar_t* dest, const wchar_t* src );

(since C95) (until C99)

wchar_t* wcscpy( wchar_t* restrict dest, const wchar_t* restrict src );

(since C99)

errno_t wcscpy_s( wchar_t* restrict dest, rsize_t destsz,
const wchar_t* restrict src );

(since C11)

# Parameters

# Example

#include <locale.h>
#include <stdio.h>
#include <wchar.h>
 
int main(void)
{
    wchar_t* src = L"犬 means dog";
//  src[0] = L'狗' ; // this would be undefined behavior
    wchar_t dst[wcslen(src) + 1]; // +1 for the null terminator
    wcscpy(dst, src);
    dst[0] = L'狗'; // OK
 
    setlocale(LC_ALL, "en_US.utf8");
    printf("src = %ls\ndst = %ls\n", src, dst);
}

# See also