C examples for uchar.h:c16rtomb
function
<cuchar> <uchar.h>
Convert 16-bit character to multibyte sequence
size_t c16rtomb ( char * pmb, char16_t c16, mbstate_t * ps );
Parameter | Description |
---|---|
pmb | an array to hold a multibyte character. |
c16 | 16-bit character of type char16_t. |
ps | a mbstate_t object that defines a conversion state. |
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.
#pragma warning(disable:4996)/*from w ww.j a va 2 s . co m*/ #define _CRT_SECURE_NO_WARNINGS #include <wchar.h> #include <uchar.h> #include <stdio.h> #include <stdlib.h> int main() { const char16_t* pt = u"this is a test\u00e9"; char buffer[123]; size_t length; mbstate_t mbs; mbrlen(NULL, 0, &mbs); while (*pt) { length = c16rtomb(buffer, *pt, &mbs); if ((length == 0) || (length>MB_CUR_MAX)) break; for (int i = 0; i<length; ++i) putchar(buffer[i]); ++pt; } return 0; }