Home >Backend Development >C++ >In C language, what is the translation of mbtowc function?

In C language, what is the translation of mbtowc function?

王林
王林forward
2023-08-27 15:33:09605browse

In C language, what is the translation of mbtowc function?

C library function int mbtowc(whcar_t *pwc, const char *str, size_t n)Convert a multi-byte sequence to wide characters.

The following is the declaration of the mbtowc() function.

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

The parameters are as follows:

  • pwc − This is a pointer to a wchar_t type object.

  • #str − This is a pointer to the first byte of a multibyte character.

  • #str − This is a pointer to the first byte of a multibyte character.

  • #n − This is the maximum number of bytes to check for character length.

The return value is as follows:

  • If str is not NULL, the mbtowc() function returns the number of bytes consumed starting from str. If Returns 0 if s points to a null byte, or -1 on failure.

  • If str is NULL, the mbtowc() function returns a non-zero value, indicating that the encoding has a non-trivial shift state, or zero if the encoding is stateless.

Example

#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 </p><p>", mb );
   return(0);
}

Output

???

The above is the detailed content of In C language, what is the translation of mbtowc function?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete