ILE C/C++ Run-Time Library Functions


wctomb() -- Convert Wide Character to Multibyte Character

Format

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

Language Level: ANSI

Threadsafe: No. Use wcrtomb() instead.

Description

The wctomb() function converts the wchar_t value of character into a multibyte array pointed to by string. If the value of character is 0, the function is left in the initial shift state. At most, the wctomb() function stores MB_CUR_MAX characters in string.

The conversion of the wide character is the same as described in wcstombs(). See this function for a Unicode example.

Return Value

The wctomb() function returns the length in bytes of the multibyte character. The value -1 is returned if character is not a valid multibyte character. If string is a NULL pointer, the wctomb() function returns nonzero if shift-dependent encoding is used, or 0 otherwise.

If a conversion error occurs, errno may be set to ECONVERT.

Example that uses wctomb()

This example converts the wide character c to a multibyte character.


#include <stdio.h>
#include <stdlib.h>
#include <wcstr.h>
 
#define SIZE 40
 
int main(void)
{
  static char  buffer[ SIZE ];
  wchar_t wch = L'c';
  int length;
 
  length = wctomb( buffer, wch );
  printf( "The number of bytes that comprise the multibyte "
             "character is %i\n", length );
  printf( "And the converted string is \"%s\"\n", buffer );
}
 
/****************  Output should be similar to:  ******************
 
The number of bytes that comprise the multibyte character is 1
And the converted string is "c"
*/

Related Information


[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]