Export (0) Print
Expand All
div
eof
Expand Minimize
This topic has not yet been rated - Rate this topic

wctomb, _wctomb_l

Convert a wide character to the corresponding multibyte character. More secure versions of these functions are available; see wctomb_s, _wctomb_s_l.

int wctomb(
   char *mbchar,
   wchar_t wchar 
);
int _wctomb_l(
   char *mbchar,
   wchar_t wchar,
   _locale_t locale
);
mbchar

The address of a multibyte character.

wchar

A wide character.

If wctomb converts the wide character to a multibyte character, it returns the number of bytes (which is never greater than MB_CUR_MAX) in the wide character. If wchar is the wide-character null character (L'\0'), wctomb returns 1. If the target pointer mbchar is NULL, wctomb returns 0. If the conversion is not possible in the current locale, wctomb returns –1 and errno is set to EILSEQ.

The wctomb function converts its wchar argument to the corresponding multibyte character and stores the result at mbchar. You can call the function from any point in any program. wctomb uses the current locale for any locale-dependent behavior; _wctomb_l is identical to wctomb except that it uses the locale passed in instead. For more information, see Locale.

wctomb validates its parameters. If mbchar is NULL, the invalid parameter handler is invoked, as described in Parameter Validation. If execution is allowed to continue, errno is set to EINVAL and the function returns -1.

Routine

Required header

wctomb

<stdlib.h>

For additional compatibility information, see Compatibility in the Introduction.

This program illustrates the behavior of the wctomb function.

// crt_wctomb.cpp
// compile with: /W3
#include <stdio.h>
#include <stdlib.h>

int main( void )
{
   int i;
   wchar_t wc = L'a';
   char *pmb = (char *)malloc( MB_CUR_MAX );

   printf( "Convert a wide character:\n" );
   i = wctomb( pmb, wc ); // C4996
   // Note: wctomb is deprecated; consider using wctomb_s
   printf( "   Characters converted: %u\n", i );
   printf( "   Multibyte character: %.1s\n\n", pmb );
}
Convert a wide character: Characters converted: 1 Multibyte character: a

Not applicable. To call the standard C function, use PInvoke. For more information, see Platform Invoke Examples.

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.