RAD Studio
ContentsIndex
PreviousUpNext
wctomb

Header File 

stdlib.h  

Category 

Conversion Routines, Memory and String Manipulation Routines 

Prototype 

int wctomb(char *s, wchar_t wc); 

Description 

Converts wchar_t code to a multibyte character. 

If s is not null, wctomb determines the number of bytes needed to represent the multibyte character corresponding to wc (including any change in shift state). The multibyte character is stored in s. At most MB_CUR_MAX characters are stored. If the value of wc is zero, wctomb is left in the initial state. 

The behavior of wctomb is affected by the setting of LC_CTYPE category of the current locale. 

Return Value 

If s is a NULL pointer, wctomb returns a nonzero value if multibyte character encodings do have state-dependent encodings, and a zero value if they do not. 

If s is not a NULL pointer, wctomb returns -1 if the wc value does not represent a valid multibyte character. Otherwise, wctomb returns the number of bytes that are contained in the multibyte character corresponding to wc. In no case will the return value be greater than the value of MB_CUR_MAX macro. 

Example  

#include <stdio.h>
#include <stdlib.h>
void main(void)
{
  int x;
  wchar_t wc = L'a';
  char *pmbNULL = NULL;
  char *pmb = (char *)malloc(sizeof( char ));
  printf (" Convert a wchar_t array into a multibyte string:\n");
  x = wctomb( pmb, wc);
  printf ("Character converted: %u\n", x);
  printf ("Multibyte string: %1s\n\n",pmb);
  printf (" Convert when target is NULL\n");
  x = wctomb( pmbNULL, wc);
  printf ("Character converted: %u\n",x);
  printf ("Multibyte stri ng: %1s\n\n",pmbNULL);
        
}

Portability

POSIX 
Win32 
ANSI C 
ANSI C++ 
Copyright(C) 2008 CodeGear(TM). All Rights Reserved.
What do you think about this topic? Send feedback!