wcscat, wcscat_s - cppreference.com (original) (raw)
| Defined in header <wchar.h> | ||
|---|---|---|
| (1) | ||
| wchar_t *wcscat( wchar_t *dest, const wchar_t *src ); | (since C95) (until C99) | |
| wchar_t *wcscat( wchar_t *restrict dest, const wchar_t *restrict src ); | (since C99) | |
| errno_t wcscat_s( wchar_t *restrict dest, rsize_t destsz, const wchar_t *restrict src ); | (2) | (since C11) |
Appends a copy of the wide string pointed to by
srcto the end of the wide string pointed to bydest. The wide charactersrc[0]replaces the null terminator at the end ofdest. The resulting wide string is null-terminated. The behavior is undefined if the destination array is not large enough for the contents of bothstranddestand the terminating null wide character. The behavior is undefined if the strings overlap.Same as (1), except that it may clobber the rest of the destination array (from the last character written to
destsz) with unspecified values and that the following errors are detected at runtime and call the currently installed constraint handler function:
srcordestis a null pointerdestszis zero or greater than RSIZE_MAX/sizeof(wchar_t)- there is no null terminator in the first
destszwide characters ofdest - truncation would occur (the available space at the end of
destwould not fit every wide character, including the null terminator, ofsrc) - overlap would occur between the source and the destination strings
As with all bounds-checked functions, wcscat_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 constant 1 before including <wchar.h>.
[edit] Parameters
| dest | - | pointer to the null-terminated wide string to append to |
|---|---|---|
| src | - | pointer to the null-terminated wide string to copy from |
| destsz | - | maximum number of characters to write, typically the size of the destination buffer |
[edit] Return value
returns a copy of
destreturns zero on success, returns non-zero on error. Also, on error, writes L'\0' to dest[0] (unless
destis a null pointer ordestszis zero or greater than RSIZE_MAX/sizeof(wchar_t)).
[edit] Example
#include <wchar.h> #include <stdio.h> #include <locale.h> int main(void) { wchar_t str[50] = L"Земля, прощай."; wcscat(str, L" "); wcscat(str, L"В добрый путь."); setlocale(LC_ALL, "en_US.utf8"); printf("%ls", str); }
Output:
Земля, прощай. В добрый путь.
[edit] References
C17 standard (ISO/IEC 9899:2018):
7.29.4.3.1 The wcscat function (p: 315)
K.3.9.2.2.1 The wcscat_s function (p: 466)
C11 standard (ISO/IEC 9899:2011):
7.29.4.3.1 The wcscat function (p: 432)
K.3.9.2.2.1 The wcscat_s function (p: 642-643)
C99 standard (ISO/IEC 9899:1999):
7.24.4.3.1 The wcscat function (p: 378)