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 a wide character where the result will be stored, or `NULL` if no storage is needed.
2nd Parameter Type : const char *
Pointer to read-only string
2nd Parameter
Pointer to the multibyte character sequence to convert, or `NULL` to test the conversion state.
3rd Parameter Type : size_t
Platform-specific unsigned type for array indices and memory sizes.
3rd Parameter
The maximum number of bytes to process from the multibyte character sequence.
4th Parameter Type : mbstate_t *
A pointer to an `mbstate_t` object that represents the current shift state for multibyte to wide character conversions. This pointer allows modification of the state during the conversion process.
4th Parameter
Pointer to a `mbstate_t` object representing the current shift state, or `NULL` to use the internal static state.
Read more about parameters of mbrtowc in parameters section
The mbrtowcfunction in C language Converts a multibyte sequence to a wide character.
The mbrtowc function converts a multibyte character to a wide character. It examines at most n bytes from the multibyte string pointed to by s to determine the number of bytes needed to complete the next multibyte character. If a valid multibyte sequence is found, it is converted to a wide character and stored in the location pointed to by pwc (if pwc is not NULL).
The mbrtowcfunction takes 4
parameters:
•
wchar_t * `pwc`: Pointer to a wide character where the result will be stored, or `NULL` if no storage is needed.
•
const char * `s`: Pointer to the multibyte character sequence to convert, or `NULL` to test the conversion state.
•
size_t `n`: The maximum number of bytes to process from the multibyte character sequence.
•
mbstate_t * `ps`: Pointer to a `mbstate_t` object representing the current shift state, or `NULL` to use the internal static state.
Converts a multibyte character sequence pointed to by `s` into a wide character, storing the result in `pwc`. Considers at most `n` bytes, respecting the current conversion state in `ps`. Returns the number of bytes processed, 0 if the character is null, or `(size_t)-1` for an encoding error. If `s` is `NULL`, the function checks if the conversion state is independent.
The mbrtowc function return value :
Returns: 0 if s points to a null character, the number of bytes that constitute the converted multibyte character, (size_t)(-2) if the next n bytes contribute to an incomplete (but potentially valid) multibyte character, or (size_t)(-1) if an encoding error occurs
Output
This example demonstrates basic usage of mbrtowc to convert multibyte characters to wide characters.