The wctomb () function in C
The function int wctomb (char * str, wchar) converts the wide char into its multi-byte representation and stores it at the beginning of the character array pointed to by str .
Declare the function wctomb () in C
Below is the declaration for wctomb () in C:
int wctomb ( char * str , wchar )
Parameters
str : is a pointer to an array large enough to hold char multibytes
wchar: is a wide character of type wchar_t.
Returns the value
If str is not NULL, wctomb () returns the number of bytes that were written to the byte array at str. If you can't represent wchar in multibyte sequence form, this function returns -1.
If str is NULL, the wctomb () function returns a non-zero value if the encoding is status, or value 0 if the encoding is non-state.
For example
The following C program illustrates the usage of wctomb () in C:
#include #include int main () { int i ; wchar_t wc = L 'a' ; char * pmbnull = NULL ; char * pmb = ( char *) malloc ( sizeof ( char )); printf ( "Chuyen doi wide char:n" ); i = wctomb ( pmb , wc ); printf ( "Cac ky tu duoc chuyen doi: %un" , i ); printf ( "Multibyte char: %.1sn" , pmb ); printf ( "Co gang thuc hien thao tac chuyen doi khi dich la NULL:n" ); i = wctomb ( pmbnull , wc ); printf ( "Cac ky tu duoc chuyen doi: %un" , i ); /* lenh sau se khong in bat ky gia tri nao */ printf ( "Multibyte char: %.1sn" , pmbnull ); return ( 0 ); }
Compiling and running the above C program will result:
According to Tutorialspoint
Last lesson: The function mbtowc () in C
Next article: string.h in C
You should read it
- The function mblen () in C
- Call the function by value in C ++
- The function mbstowcs () in C
- Call the function by pointer in C ++
- Function in programming C
- The function mbtowc () in C
- The function wcstombs () 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