wcsrtombs - C wchar.h

C examples for wchar.h:wcsrtombs

Type

function

From


<cwchar>
<wchar.h>

Description

Convert wide-character string to multibyte string

Prototype

size_t wcsrtombs (char* dest, const wchar_t** src, size_t max, mbstate_t* ps);

Parameters

Parameter Description
dest a C string of max bytes.
src C wide string to be translated
max Maximum number of bytes characters to save to dest.
ps a conversion state.

Return Value

The number of bytes written to dest.

On error, -1 is returned.

Demo Code


#include <stdio.h>
#include <wchar.h>

int main() {/*from w w w  .  j ava2 s.c o m*/
  const wchar_t str[] = L"this is a test test";

  const wchar_t * p;

  mbstate_t mbs;

  char buffer[32];

  int ret;

  mbrlen (NULL,0,&mbs);    /* initialize mbs */

  printf ("wchar_t string: %ls \n",str);

  p = str;

  ret = wcsrtombs ( buffer, &p, sizeof(buffer), &mbs );

  if (ret==32) 
     buffer[31]='\0';

  if (ret) 
     printf ("multibyte string: %s \n",buffer);

  return 0;
}

Related Tutorials