c32rtomb - C uchar.h

C examples for uchar.h:c32rtomb

Type

function

from

<cuchar>

Description

Convert 32-bit character to multibyte sequence

Prototype

size_t c32rtomb ( char * pmb, char32_t c32, mbstate_t * ps );

Parameters

Parameter Description
pmb an array to hold a multibyte sequence.
c32 32-bit character of type char32_t.
ps Pointer to a mbstate_t object that defines a conversion state.

Return Value

On success, return the size of the multibyte sequence written at pmb in bytes.

If there is no character correspondence, the function returns -1 and sets errno to EILSEQ.

If pmb is a null pointer, the function stores no bytes at pmb, and returns zero.

Demo Code


#pragma warning(disable:4996)// w  w  w . j  a v  a2  s .  com
#define _CRT_SECURE_NO_WARNINGS

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

int main() {
  char32_t* pt = U"this is a test\u00e9";
  char buffer [123];
  size_t length;
  mbstate_t mbs;

  mbrlen (NULL,0,&mbs);

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

  return 0;
}

Related Tutorials