The function wcstombs () in C
Function size_t wcstombs (char * str, const wchar_t * pwcs, size_t n) convert wide-char string defined by pwcs into a multibyte string starting at str. Almost all n bytes are written to str ..
Function size_t wcstombs (char * str, const wchar_t * pwcs, size_t n) convert wide-char string defined by pwcs into a multibyte string starting at str. Almost all n bytes are written to str .
Declare the function wcstombs () in C
Below is the declaration for wcstombs () in C:
size_t wcstombs ( char * str , const wchar_t * pwcs , size_t n )
Parameters
str : This is a pointer to an array of char elements of at least n bytes in length.
pwcs : is a wide-character string that needs to be converted.
n : maximum number of bytes to be written to str.
Returns the value
This function returns the number of bytes (not characters) that were converted and written to str, except for the ending null character. If a multibyte char is encountered, this function returns -1.
For example
The following C program illustrates the usage of wcstombs () in C:
#include #include #define BUFFER_SIZE 50 int main () { size_t ret ; char * MB = ( char *) malloc ( BUFFER_SIZE ); wchar_t * WC = L "https://QTM.com/thu-vien-c/index.jsp" ; /* chuyen doi thanh chuoi wide-character */ ret = wcstombs ( MB , WC , BUFFER_SIZE ); printf ( "Cac ky tu duoc chuyen doi = %un" , ret ); printf ( "Multibyte char = %snn" , MB ); return ( 0 ); }
Compiling and running the above C program will result:
According to Tutorialspoint
Previous article: Function memcmp () in C
Next lesson: wctomb () function in C
You should read it
- The function mblen () in C
- Call the function by value in C ++
- The function mbstowcs () in C
- The wctomb () function in C
- Call the function by pointer in C ++
- Function in programming C
- The function mbtowc () in C
- The ord () function in Python
- Int () function in Python
- The function id () in Python
- Zip () function in Python
- The function dir () in Python
Maybe you are interested
Clouds on Neptune may be created by the Sun Decipher the mystery behind a photo of a 'human bone' object on NASA's Martian surface Why are microorganisms living 'so tough' on Earth but still hard to survive on Mars Police protect the planet: Light pay high, stable to doomsday, receive 200,000 USD / year from NASA Find strong evidence of life on Mars There are major changes in the atmosphere of Mars