目录

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

描述 (Description)

C库函数int mbtowc(whcar_t *pwc, const char *str, size_t n)将多字节序列转换为宽字符。

声明 (Declaration)

以下是mbtowc()函数的声明。

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

参数 (Parameters)

  • pwc - 这是指向wchar_t类型的对象的指针。

  • str - 这是指向多字节字符的第一个字节的指针。

  • n - 这是要检查字符长度的最大字节数。

返回值 (Return Value)

  • 如果str不为NULL,则mbtowc()函数返回从str开始的消耗字节数,如果s指向空字节则返回0,或者在失败时返回-1。

  • 如果str为NULL,则如果编码具有non-trivial(非平凡)的移位状态,则mbtowc()函数返回非零;如果编码是无状态的,则返回零。

例子 (Example)

以下示例显示了mbtowc()函数的用法。

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main () {
   char *str = "This is iowiki.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);
}

让我们编译并运行上面的程序,它将产生以下结果,它将是多字节的,一种二进制输出。

???
↑回到顶部↑
WIKI教程 @2018