Export (0) Print
Expand All
div
eof
Expand Minimize

wctomb, _wctomb_l 

Convert a wide character to the corresponding multibyte character. These functions are deprecated because more secure versions 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
);

Parameters

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.

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 Compatibility

wctomb

<stdlib.h>

ANSI, Windows 95, Windows 98, Windows 98 Second Edition, Windows Millennium Edition, Windows NT 4.0, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003

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 );
}

Output

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.

Community Additions

ADD
Show:
© 2014 Microsoft