
- The C Standard Library
- C Library - Home
- C Library - <assert.h>
- C Library - <ctype.h>
- C Library - <errno.h>
- C Library - <float.h>
- C Library - <limits.h>
- C Library - <locale.h>
- C Library - <math.h>
- C Library - <setjmp.h>
- C Library - <signal.h>
- C Library - <stdarg.h>
- C Library - <stddef.h>
- C Library - <stdio.h>
- C Library - <stdlib.h>
- C Library - <string.h>
- C Library - <time.h>
- C Standard Library Resources
- C Library - Quick Guide
- C Library - Useful Resources
- C Library - Discussion
- C Programming Resources
- C Programming - Tutorial
- C - Useful Resources
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
C library function - mbtowc()
Description
The C library function int mbtowc(whcar_t *pwc, const char *str, size_t n) converts a multibyte sequence to a wide character.
Declaration
Following is the declaration for mbtowc() function.
int mbtowc(whcar_t *pwc, const char *str, size_t n)
Parameters
pwc − This is the pointer to an object of type wchar_t.
str − This is the pointer to the first byte of a multi-byte character.
n − This is the maximum number of bytes to be checked for character length.
Return Value
If str is not NULL, the mbtowc() function returns the number of consumed bytes starting at str, or 0 if s points to a null byte, or -1 upon failure.
If str is NULL, the mbtowc() function returns non-zero if the encoding has non-trivial shift state, or zero if the encoding is stateless.
Example
The following example shows the usage of mbtowc() function.
#include <stdio.h> #include <stdlib.h> #include <string.h> int main () { char *str = "This is tutorialspoint.com"; wchar_t mb[100]; int len; len = mblen(NULL, MB_CUR_MAX); mbtowc(mb, str, len*strlen(str) ); wprintf(L"%ls \n", mb ); return(0); }
Let us compile and run the above program that will produce the following result which will be in multi-byte, a kind of binary output.
???