User Tools

Site Tools


Programming Reference/Librarys

Question & Answer

Q&A is closed



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


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
#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";
   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" converted.

on the occasion of the current invasion of Russia in Ukraine

Russian Stop this War
c/stdlib.h/wcstombs.txt · Last modified: 2024/02/16 01:04 (external edit)

Impressum Datenschutz