C examples for wchar.h:mbsinit
function
<cwchar> <wchar.h>
int mbsinit (const mbstate_t* ps);
Checks whether ps points to a mbstate_t object that describes an initial conversion state.
The state pointed by ps can be set to the initial state by calling:
memset (ps,0,sizeof(*ps)); // ps points now to a zero-valued object
Parameter | Description |
---|---|
ps | Pointer to an mbstate_t object. |
A non-zero value if ps can describe an initial conversion state, or if ps is a null pointer.
Otherwise, a zero value is returned.
#pragma warning(disable:4996)/*from w w w . j av a 2 s.co m*/ #define _CRT_SECURE_NO_WARNINGS #include <wchar.h> #include <string.h> #include <stdio.h> int main() { char buffer[80]; mbstate_t mbst; const wchar_t wcs[] = L"this is a mbsinit example"; const wchar_t * p; p = wcs; if (!mbsinit(&mbst)) memset(&mbst, 0, sizeof(mbst)); /* set to initial state */ wcsrtombs(buffer, &p, 80, &mbst); printf(buffer); return 0; }