What is wcscpy in C?

The wcscpy function in C copies a wide string to a specified location. wcscpy copies all characters prior to the null character.

The process is illustrated below:

Note: A wide string is comprised of characters from the Unicode character set.

To use the wcscpy function, you will need to include the <wchar.h> library in the program, as shown below:

#include <wchar.h>

The prototype of the wcscpy function is shown below:

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

Parameters

The wcscpy function takes the following two wchar_t* objects as parameters:

  • dest: destination string
  • src: null-terminated source string

Return Value

The wcscpy function copies the src string to the dest string and returns a pointer to the altered dest string.

The behavior of the wcscpy function is undefined in the following cases:

  • The memory allocated for the dest string is not large enough.
  • The src and dest strings overlap.

Example

The code below shows how the wcscpy function works in C:

#include <stdio.h>
#include <wchar.h>
int main() {
// initializing strings
wchar_t src[] = L"Learning wcscpy with Educative!";
wchar_t dst[40];
// copying string
wcscpy(dst, src);
// printing new dest string
printf("%ls", dst);
return 0;
}

Explanation

First, two wide strings are declared for the source and destination addresses. The ‘L’ identifier in line 7 informs the compiler that the Unicode character set is being used.

The wcscpy function proceeds to copy the source string to the destination address in line 11. The updated value of the string is output.

Free Resources

Copyright ©2026 Educative, Inc. All rights reserved