Table of Contents

wcstombs

    #include <stdlib.h>
    size_t wcstombs(char *str, const wchar_t *pwcs, size_t n); 
 

Description

wcstombs converts a wide character string into a multibyte character string.
conversion stops after the size n is reached.

The behavior of wcstombs is affected by the LC_CTYPE category of the current locale

str = destination string
pwcs = pointer to wide string
n = chars to convert

  <setlocale.h> is for this example nessesary

wcstombs C Sourcecode Example

/* 
 * wcstombs example code
 * http://code-reference.com/c/stdlib.h/wcstombs 
 */
#include <stdio.h>
#include <stdlib.h>
#include <locale.h> /* setlocale function */
 
int main(void)
{
   char str[60];
   wchar_t *pwcs = L"wcstombs tést äüö for code-reference.com";
   size_t count = 60;
   size_t n;
 
   setlocale(LC_ALL, "");
   n = wcstombs(str, pwcs, count);
 
   printf("%d characters from string \"%s\" converted.\n", n, str);
 
   return 0;
 
}

output of wcstombs example

  user@host:~$  ./wcstombs 
  44 characters from string "wcstombs tést äüö for code-reference.com" converted.