wctomb()

Convert a wide character into a multibyte character

Synopsis:

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

Arguments:

s
NULL, or a pointer to a location where the function can store the multibyte character.
wc
The wide character that you want to convert.

Library:

libc

Use the -l c option to qcc to link against this library. This library is usually included automatically.

Description:

The wctomb() function determines the number of bytes required to represent the multibyte character corresponding to the code contained in wc. If s isn't NULL, the multibyte character representation is stored in the array it points to. At most MB_CUR_MAX characters are stored.

Returns:

  • If s is NULL:
    0
    The wctomb() function uses locale specific multibyte character encoding that's not state-dependent.
    >0
    The function is state-dependent.
  • If s isn't NULL:
    -1
    If the value of wchar doesn't correspond to a valid multibyte character.
    x
    The number of bytes that comprise the multibyte character corresponding to the value of wchar.

Examples:

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

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

int main( void )
  {
    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 );
    return EXIT_SUCCESS;
  }

This produces the output:

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

Classification:

ANSI, POSIX 1003.1

Safety:  
Cancellation point No
Interrupt handler No
Signal handler Yes
Thread Yes

Last modified: 2013-12-23

comments powered by Disqus