Namespaces
Variants
Views
Actions

Difference between revisions of "c/string/wide/wcscat"

From cppreference.com
< c‎ | string‎ | wide
m (c95)
(_s, including dr 433)
Line 1: Line 1:
{{c/title| wcscat}}
+
{{c/title| wcscat | wcscat_s}}
 
{{c/string/wide/navbar}}
 
{{c/string/wide/navbar}}
{{ddcl | header=wchar.h |notes={{mark since c95}}|
+
{{dcl begin}}
 +
{{dcl header | wchar.h}}
 +
{{dcl rev begin|num=1}}
 +
{{dcl | since=c95 | until=c99 |
 
wchar_t *wcscat( wchar_t *dest, const wchar_t *src );
 
wchar_t *wcscat( wchar_t *dest, const wchar_t *src );
 
}}
 
}}
 
+
{{dcl | since=c99 |
Appends a wide string pointed to by {{tt|src}} to a wide string pointed to by {{tt|dest}}. The resulting wide string is null-terminated. If the strings overlap, the behavior is undefined.  
+
wchar_t *wcscat(wchar_t *restrict dest, const wchar_t *restrict src);
 +
}}
 +
{{dcl rev end}}
 +
{{dcl |num=2| since=c11 |
 +
errno_t wcscat_s(wchar_t *restrict dest, rsize_t destsz,
 +
                const wchar_t *restrict src);
 +
}}
 +
{{dcl end}}
 +
@1@ Appends a copy of the wide string pointed to by {{tt|src}} to the end of the wide string pointed to by {{tt|dest}}. The wide character {{tt|src[0]}} replaces the null terminator at the end of {{tt|dest}}. The resulting wide string is null-terminated. The behavior is undefined if the destination array is not large enough for the contents of both {{tt|str}} and {{tt|dest}} and the terminating null wide character. The behavior is undefined if the strings overlap.
 +
@2@ Same as {{v|1}}, except that it may clobber the rest of the destination array (from the last character written to {{tt|destsz}}) with unspecified values and that the following errors are detected at runtime and call the currently installed [[c/error/set_constraint_handler_s|constraint handler]] function:
 +
:* {{tt|src}} or {{tt|dest}} is a null pointer
 +
:* {{tt|destsz}} is zero or greater than {{c|RSIZE_MAX/sizeof(wchar_t)}}
 +
:* there is no null terminator in the first {{tt|destsz}} bytes of {{tt|dest}}
 +
:* truncation would occur (the available space at the end of {{tt|dest}} would not fit every wide character, including the null terminator, of {{tt|src}})
 +
:* overlap would occur between the source and the destination strings
 +
:As all bounds-checked functions, {{tt|wcscat_s}} is only guaranteed to be available if {{c|__STDC_LIB_EXT1__}} is defined by the implementation and if the user defines {{c|__STDC_WANT_LIB_EXT1__}} to the integer constant {{c|1}} before including {{tt|wchar.h}}.
  
 
===Parameters===
 
===Parameters===
Line 11: Line 29:
 
{{par | dest | pointer to the null-terminated wide string to append to}}
 
{{par | dest | pointer to the null-terminated wide string to append to}}
 
{{par | src | pointer to the null-terminated wide string to copy from}}
 
{{par | src | pointer to the null-terminated wide string to copy from}}
 +
{{par | destsz | maximum number of characters to write, typically the size of the destination buffer}}
 
{{par end}}
 
{{par end}}
  
 
===Return value===
 
===Return value===
{{tt|dest}}
+
@1@ returns a copy of {{tt|dest}}
 +
@2@ returns zero on success, returns non-zero on error. Also, on error, writes {{c|L'\0'}} to {{c|dest[0]}} (unless {{tt|dest}} is a null pointer or {{tt|destsz}} is zero or greater than {{c|RMAX_SIZE/sizeof(wchar_t)}}).
  
 
===Example===
 
===Example===
Line 20: Line 40:
 
  |
 
  |
 
  | code=
 
  | code=
 +
#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=
 
  | output=
 +
Земля, прощай. В добрый путь.
 
}}
 
}}
  
Line 26: Line 59:
 
{{dsc begin}}
 
{{dsc begin}}
 
{{dsc inc | c/string/wide/dsc wcsncat}}
 
{{dsc inc | c/string/wide/dsc wcsncat}}
 +
{{dsc inc | c/string/byte/dsc strcat}}
 
{{dsc inc | c/string/wide/dsc wcscpy}}
 
{{dsc inc | c/string/wide/dsc wcscpy}}
 
{{dsc see cpp | cpp/string/wide/wcscat}}
 
{{dsc see cpp | cpp/string/wide/wcscat}}

Revision as of 11:04, 23 February 2015

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)
1) Appends a copy of the wide string pointed to by src to the end of the wide string pointed to by dest. The wide character src[0] replaces the null terminator at the end of dest. The resulting wide string is null-terminated. The behavior is undefined if the destination array is not large enough for the contents of both str and dest and the terminating null wide character. The behavior is undefined if the strings overlap.
2) 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:
  • src or dest is a null pointer
  • destsz is zero or greater than RSIZE_MAX/sizeof(wchar_t)
  • there is no null terminator in the first destsz bytes of dest
  • truncation would occur (the available space at the end of dest would not fit every wide character, including the null terminator, of src)
  • overlap would occur between the source and the destination strings
As 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.

Contents

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

Return value

1) returns a copy of dest
2) returns zero on success, returns non-zero on error. Also, on error, writes L'\0' to dest[0] (unless dest is a null pointer or destsz is zero or greater than RMAX_SIZE/sizeof(wchar_t)).

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:

Земля, прощай. В добрый путь.

See also

appends a certain amount of wide characters from one wide string to another
(function) [edit]
concatenates two strings
(function) [edit]
(C95)(C11)
copies one wide string to another
(function) [edit]