Name
wcstombs
Synopsis
Converts a wide-character string into a multibyte string
#include <stdlib.h> size_twcstombs
( char * restrictdest
, const wchar_t * restrictsrc
, size_tn
);
The wcstombs()
function
converts one or more wide characters from the array addressed by
src
into a string of multibyte
characters, beginning in the initial parse state, and stores the
results in the array of char
addressed by dest
. The third argument,
n
, specifies the maximum number of
characters that can be written to the output buffer; conversion ends
either when a terminating null character has been written to the
output buffer, or when writing another multibyte character would
exceed the buffer size of n
bytes. The
wcstombs()
function returns the
number of bytes written, not including the terminating null
character if any, or -1 if an encoding error occurs. The conversion
performed on each wide character is the same as that which would be
performed by the wctomb()
function.
Tip
The wcstombs()
function
terminates the resulting multibyte string with a null character
('\0'
) only if it has not yet
written the maximum number of characters specified by the third
argument! If the return value is the same as the specified limit,
then the resulting string has not been terminated.
Example
wchar_t fmt_amount[128] = { L'\0' }; wchar_t prefix[32] = L"-"; wchar_t suffix[32] = L""; wchar_t number[128] = L"123.456,78"; char ...
Get C in a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.