The wcrtomb() function in C/C++ converts a wide character to its narrow multibyte representation. The wide character wc is translated to its multibyte equivalent and stored in the array pointed by s. The function returns the length in bytes of the equivalent multibyte sequence pointed by s.
size_t wcrtomb( char* s, wchar_t wc, mbstate_t* ps )
Parameters:The function accepts three mandatory parameters which are described below:
- s: specifies the pointer to an array large enough to hold a multibyte sequence
- wc: specifies the wide character to convert.
- ps: specifies the pointer to the conversion state used when interpreting the multibyte string
Return values: The function returns two value as below:
- On success, it returns the number of bytes written to the character array whose first element is pointed to by s.
- Otherwise, it returns -1 and errno is set to EILSEQ.
Below programs illustrate the above function:
Size of z is 1 bytes Size of Ã? is 2 bytes Size of æ°´ is 3 bytes Size of ð?? is 4 bytes
Program 2 :
Size of u Ì_e is 1 bytes Size of Ã?Ì_e is 2 bytes Size of ÃµÌ_e is 2 bytes Size of ÆµÌ_e is 2 bytes
- Function Overloading vs Function Overriding in C++
- What happens when a virtual function is called inside a non-virtual function in C++
- div() function in C++
- fma() function in C++
- log() function in C++
- exp() function C++
- arc function in C
- wmemcmp() function in C/C++
- atan2() function in C++ STL
- iswcntrl() function in C/C++
- bitset all() function in C++ STL
- towctrans() function in C/C++
- mktime() function in C++ STL
- bitset set() function in C++ STL
- wcstoul() function in C/C++
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.