function
<cwchar>
mbsinit
int mbsinit (const mbstate_t* ps);
Check if initial conversion state
Checks whether ps points to a mbstate_t object that describes an initial conversion state.
A zero-valued mbstate_t object always describes an initial conversion state, although other values may also represent such state (depending on the particular library implementation). This function returns non-zero for any mbstate_t object representing an initial state, or if ps is a null pointer.
This function does not change the state identified by ps. Typical ways to make the state pointed by ps an initial state are:
|
memset (ps,0,sizeof(*ps)); // ps points to zero-valued object
|
or:
|
mbrlen (NULL,0,ps); // *ps set to an initial state
|
Parameters
- ps
- Pointer to an mbstate_t object.
Return Value
A non-zero value if ps points to a mbstate_t object that describes an initial conversion state, or if ps is a null pointer.
Otherwise, a zero value is returned.
Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
|
/* mbsinit example */
#include <wchar.h>
#include <string.h>
#include <stdio.h>
int main()
{
char buffer[80];
mbstate_t mbst;
const wchar_t wcs [] = L"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;
}
|
Output:
See also
- wcrtomb
- Convert wide character to multibyte sequence (function
)
- mbrtowc
- Convert multibyte sequence to wide character (function
)
- wcsrtombs
- Convert multibyte string to wide-character string (function
)
- mbsrtowcs
- Convert multibyte string to wide-character string (function
)