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 .
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
Transparent solar cells help smartphones charge themselves with sunlight
How to charge phone with battery
6 reasons why phones charge slowly
iOS bug causes iPhone to crash when entering these 4 characters
Laptop automatically stops charging when playing games - Fast processing
How to properly plug in the iPhone charger according to Apple's recommendations