Home > Backend Development > C++ > body text

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

王林
Release: 2023-08-27 15:33:09
forward
570 people have browsed it

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)
Copy after login

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);
}
Copy after login

Output

???
Copy after login

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!