Previous Page
Next Page

wcstombs

Converts a wide-character string into a multibyte string

#include <stdlib.h>
size_t wcstombs ( char * restrict dest , const wchar_t * restrict src ,
                 size_t n  );

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.

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 output_amount[256]; wcscpy( fmt_amount, prefix ); wcscat( fmt_amount, number ); wcscat( fmt_amount, suffix ); if ( -1 != wcstombs( output_amount, fmt_amount, 256 )) printf( "Full amount: %s\n", output_amount );

See Also

wcsrtombs( ), mbstowcs( ), and wcrtomb( ); wctomb( ), mbtowc( ), and mbrtowc( )


Previous Page
Next Page