Easy Tutorial
❮ C Exercise Example76 C Examples Array Largest Element ❯

C Library Function - mbtowc()

C Standard Library - <stdlib.h>

Description

The C library function int mbtowc(wchart *pwc, const char *str, sizet n) converts a multi-byte sequence to a wide character.

Declaration

Here is the declaration for the mbtowc() function.

int mbtowc(wchar_t *pwc, const char *str, size_t n)

Parameters

Return Value

Example

The following example demonstrates the use of the mbtowc() function.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main()
{
   char *str = "这里是 tutorialpro.org";
   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's compile and run the above program, which will produce the following result as it outputs the result in multi-byte format, which is a binary output.

???

C Standard Library - <stdlib.h>

❮ C Exercise Example76 C Examples Array Largest Element ❯