Programming Reference/Librarys
Question & Answer
Q&A is closed
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 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; }
user@host:~$ ./wcstombs 44 characters from string "wcstombs tést äüö for code-reference.com" converted.