What is wcscat_s in C?
The wcscat_s function
The wcscat_s function is defined in the wchar.h standard library and is used to copy wide characters from one array to another. The structure of the wcscat_s function is as follows:
errno_t wcscat_s(whcar_t * dest, rsize_t destsz, const whchar_t * src);
Parameters
destis a pointer to a null-terminated wide string to append to.srcis a pointer to a null-terminated wide string to copy from.destszis the maximum number of characters to copy.
Return value
- Zero upon success
- Non-zero upon error
Example usage of the wcscat_s function
The following code copies characters from one array to another using the wcscat_s function:
#include<stdio.h>#include<wchar.h>int main() {wchar_t arr_src[] = L"Hello_World";wchar_t arr_dest[13];wcscat_s(arr_dest, 11, arr_src);wprintf(L"arr_dest: %S", arr_dest);return 0;}
Output:
arr_dest: Hello_World
Note: The function above is not supported by the GCC compiler, so you will get an
implicit declaration of function…error.
Use the following variant wcscat to get the job done:
wchar_t * wcscat(whcar_t * dest, const whchar_t * src);
All parameters are the same as wcscat_s, except that destsz is not a parameter of wcscat. The return value of wcscat is the pointer to the dest string.
Free Resources
Copyright ©2025 Educative, Inc. All rights reserved