wcstombs - C stdlib.h

C examples for stdlib.h:wcstombs

Type

function

From


<cstdlib>
<stdlib.h>

Description

Convert wide-character string to multibyte string

Prototype

size_t wcstombs (char* dest, const wchar_t* src, size_t max);

Parameters

Parameter Description
dest an array of char long enough to store the resulting sequence, at most, max bytes.
src C wide string to be translated.
max Maximum number of bytes to be written to dest.

Return Value

On success, the number of bytes written to dest.

On error, -1 value is returned.

Demo Code


#include <stdio.h>
#include <stdlib.h>

int main() {/*from w w w. j  av a2s.c om*/
  const wchar_t str[] = L"wcstombs example this is a test";
  char buffer[32];
  int ret;

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

  ret = wcstombs ( buffer, str, sizeof(buffer) );

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

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

  return 0;
}

Related Tutorials