C wcstombs() function
C wcstombs() function - Convert a wide-character string to a character string
Syntax wcstombs() function
size_t wcstombs(char *str, const wchar_t *pwcs, size_t n)
The wcstombs() function is used to convert the wide-character string pointed to by string into the multibyte array pointed to by str.
Parameters wcstombs() function
Name | Description | Required /Optional |
---|---|---|
str | This is the pointer to an array of char elements at least n bytes long. | Required |
pwcs | This is wide-character string to be converted. | Required |
n | This is the maximum number of bytes to be written to str. | Required |
Return value from wcstombs()
- If a wide-character code is encountered that does not correspond to a valid character, wcstombs() shall return (size_t)-1.
- Otherwise, the function returns the number of bytes stored in the character array, not including any terminating null byte.
Example: wcstombs() function
The following example shows the usage of wcstombs() function.
N.B.: This code is executed in windows 10
Output:
setlocale failed. string = XYZ, length = 3 setlocale failed. length = -1
C Programming Code Editor:
Previous C Programming: C mbtowc()
Next C Programming: C wctomb()