Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
Expand Minimize


Converts a wide character to the corresponding multibyte character.

int wctomb(
   char *mbchar,
   wchar_t wchar 


The address of a multibyte character.
A wide character.

Return Value

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 conversion is not possible in the current locale, wctomb returns –1.


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.


Routine Required header Compatibility
wctomb <stdlib.h> ANSI, Win 98, Win Me, Win NT, Win 2000, Win XP

For additional compatibility information, see Compatibility in the Introduction.


All versions of the C run-time libraries.


This program illustrates the behavior of the wctomb function.

// crt_wctomb.cpp
#include <stdio.h>
#include <stdlib.h>

int main( void )
   int i;
   wchar_t wc = L'a';
   char *pmbnull = NULL;
   char *pmb = (char *)malloc( sizeof( char ) );

   printf( "Convert a wide character:\n" );
   i = wctomb( pmb, wc );
   printf( "   Characters converted: %u\n", i );
   printf( "   Multibyte character: %.1s\n\n", pmb );

   printf( "Attempt to convert when target is NULL:\n" );
   i = wctomb( pmbnull, wc );
   printf( "   Characters converted: %u\n", i );
   printf( "   Multibyte character: %.1s\n", pmbnull );


Convert a wide character:
   Characters converted: 1
   Multibyte character: a

Attempt to convert when target is NULL:
   Characters converted: 0
   Multibyte character: (

See Also

Data Conversion Routines | Locale Routines | mblen | mbstowcs | mbtowc | wcstombs | WideCharToMultiByte | Run-Time Routines and .NET Framework Equivalents

© 2015 Microsoft