libtconv-0.1 manual
tconv_wcmb
unsigned int tconv_wcmb(tconv *tcP, char_t *mbP, const wchar_t * *wcPP, unsigned int max);
declared in tconv.h, include tconv.h

tcP handle of an existing tconv instance,
mbP location of a buffer where to put the multi-byte string,
wcPP location of a handle pointing at the wide-character string,
max number of characters to convert.

Function translates wide-character strings into multi-byte strings. The mbP pointed buffer needs to be big enough to store number of characters indicated by max. If max is set to 0 (zero), the function translates wide-characters, until it detects the NULL-terminating byte, that is also written into the output buffer.

If conversion succeeds, the returned value indicates the number of bytes written into the output location, without the NULL-terminating byte (if any). When it fails, the tconvError value is returned.

To perform the conversion, internal output character encoding is used.

Example
/* C source  */

#include <stdio.h>
#include "tconv.h"

void main(){
  /*
  0x105 wchar_t value of 'a' with a tail below,
  */
  const wchar_t wcB[]= { 0x105,'b','c','d','e',0};
  const wchar_t *wcP = wcB;
  tconv *tcP;
  char mbB[16];

  /* input enc. ignored; output enc. is used */
  tcP = tconv_init(NULL, "pl_PL.iso_8859-2");
  if(tconvError == tconv_wcmb(tcP, mbB, & wcP, 0))
    wprintf(L"Error at %ls", wcP);
  else
    printf("Done\nString 'mbB' is: %s", mbB);
 
  tconv_free(tcP); 
}

WARNING! According to C standards, the result of calling printf() and wprintf() one after another on the same stream (stdout), is known as "undefined behaviour". The stream should be closed and opened again to reset its character width support.

Copyright 2015 TinyIT All rights reserved
Last modified 2015-06-04