C Library Function - wcstombs()
Description
C Library Function **size_t wcstombs(char str, const wchar_t pwcs, size_t n) Converts the wide-character string pwcs into a multibyte string str in the initial shift state. At most n bytes will be written to str it.
Declaration
Below is the declaration of the wcstombs() function.
size_t wcstombs(char *str, const wchar_t *pwcs, size_t n)
Parameters
- str -- An array pointing to char elements, at least n bytes long.
- pwcs -- The wide-character string to be converted.
- n -- The maximum number of bytes to be written to str.
Return Value
This function returns the number of bytes converted and written to str, not including the terminating null character. If an invalid multibyte character is encountered, the value -1 is returned.
Example
The following example demonstrates the use of the wcstombs() function.
#include
#include
#define BUFFER_SIZE 50
int main()
{
size_t ret;
char *MB = (char *)malloc( BUFFER_SIZE );
wchar_t *WC = L"http://www.w3cschool.cc";
/* Convert wide character string */
ret = wcstombs(MB, WC, BUFFER_SIZE);
printf("要转换的字符数 = %u\n", ret);
printf("多字节字符 = %s\n\n", MB);
return(0);
}
Let's compile and run the above program, which will produce the following result:
要转换的字符数 = 23
多字节字符 = http://www.w3cschool.cc
C Standard Library -