The mbsrtowcs() function in C/C++ converts a narrow multibyte character sequence to a wide character sequence. It converts the multibyte character string whose first byte is represented by *src to corresponding wide character representation and is stored in the wide character array pointed to by dest. A maximum of len wide characters are written to dest.
size_t mbsrtowcs( wchar_t* dest, const char** src, size_t len, mbstate_t* ps )
Parameters: The function accepts four mandatory parameters which are described below:
- dest :specifies the pointer to the array where the converted wide character is stored
- ps :specifies the pointer to the conversion state object
- src :specifies the pointer to pointer to the first multibyte character to convert
- len :specifies the maximum number wide character to store
Return value : The function returns two value as below:
- the mbsrtowcs() function returns the number of wide characters written to dest excluding the terminating wide null character on success.
- if dest is a null pointer, it returns the number of wide characters that would have been written considering unlimited length.
- on conversion error, -1 is returned and errno is set to EILSEQ
Note : This function moves the src pointer to the end of the converted multibyte string. This doesn’t happen if dst==NULL
Below programs illustrate the above function :
Program 1 :
Number of wide characters written = 2 Wide character = Ý£Ý?
Program 2 :
Number of wide characters written = 4 Wide character = zÃ?æ°´ð??
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++
- Write a one line C function to round floating point numbers
- Does C support function overloading?
- How can I return multiple values from a function?
- What is the purpose of a function prototype?
- How to declare a pointer to a function?
- C function to Swap strings
- Can we call an undeclared function in C++?
- What is evaluation order of function parameters 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
- Importance of function prototype in 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 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.