[Previous]
[Contents]
[Next]

wctomb()

convert a wide character to a multibyte character

Synopsis:

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

Description:

The wctomb() function determines the number of bytes required to represent the multibyte character corresponding to the wide character contained in wc. If s isn't 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 aren't state-dependent, and nonzero otherwise.

If s isn't a NULL pointer, the wctomb() function returns:

-1
if the value of wc doesn't correspond to a valid multibyte character
len
the number of bytes that comprise the multibyte character corresponding to the value of wc.

Examples:

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

wchar_t wc = { 0x0073 };
char    mbbuffer[2];

void main()
  {
    int len;

    printf( "Character encodings are %sstate-dependent.\n",
        ( wctomb( NULL, 0 ) ) ? "" : "not " );

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

produces the output:

Character encodings are not state-dependent. 
s(1)

Classification:

ANSI

Safety:
Interrupt handler No
Signal handler Yes
Thread Yes

See also:

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


[Previous]
[Contents]
[Next]