wctomb - C stdlib.h

C examples for stdlib.h:wctomb

Type

function

From


<cstdlib>
<stdlib.h>

Description

Convert wide character to multibyte sequence

Prototype

int wctomb (char* pmb, wchar_t wc);

Parameters

Parameter Description
pmb Pointer to an array large enough to hold a multibyte sequence.
wc Wide character of type wchar_t.

Return Value

On success, the size in bytes written to pmb is returned.

On error, -1 is returned.

Demo Code


#pragma warning(disable:4996)//from  ww  w  .j av  a2  s  .  c om
#define _CRT_SECURE_NO_WARNINGS

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

int main() {
  const wchar_t str[] = L"wctomb example";
  const wchar_t* pt;
  char buffer[123];
  int i, length;

  pt = str;
  while (*pt) {
    length = wctomb(buffer, *pt);
    if (length<1) break;
    for (i = 0; i<length; ++i) printf("[%c]", buffer[i]);
    ++pt;
  }

  return 0;
}

Related Tutorials