wctomb

convert a wide character to a multibyte character

Synopsis:

#include <stdlib.h>
int wctomb( char *s, wchar_t wchar );

Description:

The wctomb() function determines the number of bytes required to represent the multibyte character corresponding to the code contained in wchar. If s is not a NULL pointer, the multibyte character representation is stored in the array pointed to by s. At most MB_CUR_MAX characters will be stored.

Returns:

If s is a NULL pointer, the wctomb() function returns zero if multibyte character encodings do not have state-dependent encoding, and non-zero otherwise.

If s is not a NULL pointer, the wctomb() function returns:

-1
if the value of wchar does not correspond to a valid multibyte character
len
the number of bytes that comprise the multibyte character corresponding to the value of wchar.

See also:

mblen(), mbstowcs(), mbtowc(), wcstombs()

Examples:

#include <stdio.h>
#include <stdlib.h>

wchar_t wchar = { 0x0073 };
char    mbbuffer[MB_CUR_MAX];

void main()
  {
    int len;

    printf( "Character encodings do %shave "
        "state-dependent \nencoding.\n",
        ( wctomb( NULL, 0 ) )
        ? "" : "not " );

    len = wctomb( mbbuffer, wchar );
    mbbuffer[len] = '\0';
    printf( "%s(%d)\n", mbbuffer, len );
  }

produces the output:

Character encodings do not have state-dependent 
encoding.
s(1)

Classification:

ANSI

Systems:

All (except DOS/PM)