mbstate_t - C wchar.h

C examples for wchar.h:mbstate_t

Type

data type

From


<cwchar>
<wchar.h>

Description

Multibyte conversion state

Demo Code


#pragma warning(disable:4996)/* w w  w .  j  a  v  a  2  s . c  om*/
#define _CRT_SECURE_NO_WARNINGS

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

int main() {
  const wchar_t* pt = L"this is a wcrtomb example";
  char buffer[123];
  size_t length, i;
  mbstate_t mbs;

  mbrlen(NULL, 0, &mbs);   /* initialize mbs */

  while (*pt) {
    length = wcrtomb(buffer, *pt, &mbs);
    if ((length == 0) || (length>MB_CUR_MAX))
      break;
    putchar('[');
    for (i = 0; i<length; ++i)
      putchar(buffer[i]);
    putchar(']');
    ++pt;
  }

  return 0;
}

Related Tutorials