C examples for stdlib.h:wctomb
function
<cstdlib> <stdlib.h>
Convert wide character to multibyte sequence
int wctomb (char* pmb, wchar_t wc);
Parameter | Description |
---|---|
pmb | Pointer to an array large enough to hold a multibyte sequence. |
wc | Wide character of type wchar_t. |
On success, the size in bytes written to pmb is returned.
On error, -1 is returned.
#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; }