mbsinit - C wchar.h

C examples for wchar.h:mbsinit

Type

function

From


<cwchar>
<wchar.h>

Prototype

int mbsinit (const mbstate_t* ps);

Description

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

Parameters

Parameter Description
ps Pointer to an mbstate_t object.

Return Value

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.

Demo Code


#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;
}

Related Tutorials