A pointer to a wide-character string, where each element is of type `wchar_t`. Used for representing text in wide-character encoding to support extended character sets.
1st Parameter
Pointer to the destination wide-character array where the converted wide characters will be stored. If `dst` is `NULL`, no conversion is performed, and the function returns the number of wide characters that would be written.
2nd Parameter Type : const char *
Pointer to read-only string
2nd Parameter
Pointer to the null-terminated multibyte character string to be converted.
3rd Parameter Type : size_t
Platform-specific unsigned type for array indices and memory sizes.
3rd Parameter
The maximum number of wide characters to write to the destination array, including the null terminator.
Read more about parameters of mbstowcs in parameters section
The mbstowcsfunction in C language Converts a multibyte string to a wide character string, not dependent on the current locale.
The mbstowcs function converts a sequence of multibyte characters to a sequence of corresponding wide characters. It stores not more than n wide characters into the array pointed to by pwcs. No more than n elements are modified in the array pointed to by pwcs. The conversion stops if a null character is encountered.
The mbstowcsfunction takes 3
parameters:
•
wchar_t * `dst`: Pointer to the destination wide-character array where the converted wide characters will be stored. If `dst` is `NULL`, no conversion is performed, and the function returns the number of wide characters that would be written.
•
const char * `src`: Pointer to the null-terminated multibyte character string to be converted.
•
size_t `n`: The maximum number of wide characters to write to the destination array, including the null terminator.
Converts a null-terminated multibyte character string to a wide-character string, storing the result in the array pointed to by `dst`. Considers at most `n` wide characters, including the null terminator. Returns the number of wide characters written (excluding the null terminator) or `(size_t)-1` if an encoding error occurs. If `dst` is `NULL`, the function returns the number of wide characters required for conversion.
The mbstowcs function return value :
Returns the number of wide characters modified, not including the terminating null character
If an invalid multibyte character is encountered, it returns (size_t)(-1)
Output
This example demonstrates basic usage of mbstowcs to convert a multibyte string to a wide character string.