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 `wchar_t` where the converted wide character will be stored. If `pwc` is `NULL`, the function only determines the length of the multibyte character.
2nd Parameter Type : const char *
Pointer to read-only string
2nd Parameter
Pointer to the multibyte character sequence to be converted. If `s` is `NULL`, the function resets the internal 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 examine in the multibyte character sequence.
Read more about parameters of mbtowc in parameters section
The mbtowcfunction in C language Converts a multibyte sequence to a single wide character.
The mbtowc function converts a multibyte character to a wide character. It examines at most n bytes of the multibyte character string pointed to by s. If s is not a null pointer, mbtowc determines the number of bytes that constitute the next multibyte character. It then converts the multibyte character to a wide character and stores it in the location pointed to by pwc (if pwc is not a null pointer).
The mbtowcfunction takes 3
parameters:
•
wchar_t * `pwc`: Pointer to a `wchar_t` where the converted wide character will be stored. If `pwc` is `NULL`, the function only determines the length of the multibyte character.
•
const char * `s`: Pointer to the multibyte character sequence to be converted. If `s` is `NULL`, the function resets the internal conversion state.
•
size_t `n`: The maximum number of bytes to examine in the multibyte character sequence.
Converts the multibyte character sequence pointed to by `s` into a wide character, storing the result in `pwc`. Considers at most `n` bytes. Returns the number of bytes processed to produce the wide character, `0` if `s` is the null character, or `-1` if an encoding error occurs. If `s` is `NULL`, the function resets the internal conversion state and returns 0.
The mbtowc function return value :
If s is a null pointer, returns nonzero if multibyte character encodings are state-dependent, and zero otherwise
If s is not a null pointer, returns: 0 if s points to a null byte, the number of bytes that constitute the converted multibyte character, or -1 if an invalid multibyte character is encountered
Output
This example demonstrates basic usage of mbtowc to convert each multibyte character in a string to a wide character.