wcrtomb

Converts a wide-character code to a multibyte character (restartable).

Library:LibC
Classification:ANSI
Service:Characters and Strings

Syntax

  #include <wchar.h> 
   
  size_t   wcrtomb (
     char        *s,
     wchar_t      wc,
     mbstate_t   *ps);
  

Parameters

s

(OUT) Points to the converted multibyte character. If no conversion is needed, this can be a NULL pointer.

wc

(IN) Specifies the wide-character code.

ps

(IN) Points to the conversion state of the character sequence. If ps is a NULL pointer, wcrtomb uses its own state, which is initialized at program startup. A thread-safe application must not pass a NULL pointer.

Return Values

If successful, returns the number of bytes in the wide-character code, including any shift sequences. Otherwise, returns -1 and sets errno to one of the following:

Decimal

Constant

Description

9

EINVAL

The ps parameter points to an object that contains an invalid conversion state.

101

EILSEQ

The wc parameter does not specify a valid wide-character code.

Remarks

The wcrtomb function determines the number of bytes needed to represent the character that corresponds to the wide character given by wc (including any shift sequences). 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 are stored.

See Also

mbsrtowcs