User Tools

Site Tools


Sidebar

Programming Reference/Librarys

Question & Answer

Q&A is closed







c:stdlib.h:mbtowc

mbtowc

    #include <stdlib.h>
        int mbtowc(whcar_t *pwc, const char *str, size_t n);
 

Description

converts a multibyte character into a wide character.

  <setlocale.h> <wchar.h> is for this example nessesary

mbtowc C Sourcecode Example

/* 
 * mbtowc example code
 * http://code-reference.com/c/stdlib.h/mbtowc 
 */
#include <stdio.h>
#include <stdlib.h> 
#include <wchar.h> /*  wint_t*/
#include <locale.h> /* setlocale*/
 
int main(void)
{
  wchar_t wchar;
  char string[] = "mbtowc: 測試字符串";
  int i=0, length=0;
 
  setlocale(LC_ALL,"");  
  while ( ( length = mbtowc ( &wchar, &string[i], MB_CUR_MAX )) != 0)
    {
      printf( "%lc", (wint_t)wchar );
      //  printf("i=%i, length=%i\n",i, length);
      i += length;
    }
  printf("\n");
return 0;
}

output of mbtowc example

  
  mbtowc: 測試字符串

on the occasion of the current invasion of Russia in Ukraine

Russian Stop this War
c/stdlib.h/mbtowc.txt · Last modified: 2024/02/16 01:04 (external edit)

Impressum Datenschutz