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
Troubleshooting Chromebook Not Charging
How to use pictures as Excel chart columns
Bleach: Characters with the most changed appearances
Why do phones need wireless charging?
How to create names with special characters, add special characters to game names, game character names
How to prevent laptop battery from charging past 80% on Windows 11