The mbrtowc() function in C/C++ converts multibyte sequence to wide characters. This function returns the length in bytes of a multibyte character. The multibyte character pointed by s is converted to a value of type wchar_t and stored at the location pointed by pwc. If s points to a null character, the function resets the shift state and returns zero after storing the wide null character at pwc.
size_t mbrtowc (wchar_t* pwc, const char* pmb, size_t max, mbstate_t* ps)
Parameter: The function accepts four parameters as described below:
- pwc : pointer to the location where the resulting wide character will be written
- s : pointer to the multibyte character string used as input
- n : limit on the number of bytes in s that can be examined
- ps : pointer to the conversion state used when interpreting the multibyte string
Return value: The function returns four value as follows:
- If, null wide character or if pmb is a null pointer, the function returns 0
- the number of bytes [1…n] of the multibyte character successfully converted from s
- If the max first characters of pmb form an incomplete multibyte character, the function returns length-2
- Otherwise, function returns length-1 and it sets errno to EILSEQ
Note: None of the values possibly returned is less than zero.
Below programs illustrate the above function:
Next 1 bytes are the character z Next 2 bytes are the character Ã? Next 3 bytes are the character æ°´ Next 4 bytes are the character ð??
Next 3 bytes are the character â?? Next 1 bytes are the character y Next 3 bytes are the character â?? Next 1 bytes are the character x Next 2 bytes are the character Â¬
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- What happens when a virtual function is called inside a non-virtual function in C++
- Function Overloading vs Function Overriding in C++
- Difference between Virtual function and Pure virtual function in C++
- How to call some function before main() function in C++?
- How to call function within function in C or C++
- Difference between user defined function and library function in C/C++
- Difference between virtual function and inline function in C++
- Can we call an undeclared function in C++?
- Can we use function on left side of an expression in C and C++?
- Declare a C/C++ function returning pointer to array of integer pointers
- Function overloading and return type
- Function Pointer in C
- Default arguments and virtual function
- Function overloading and const keyword
- How to measure time taken by a function in C?
- Comparator function of qsort() in C
- Can we access private data members of a class without using a member or a friend function?
- Function Overloading and float in C++
- Extra brackets with function names in C/C++
- Function Interposition in C with an example of user defined malloc()
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. 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.
Improved By : shubham_singh