mbstowcs

提供: RAD Studio
移動先: 案内検索

stdlib.h:インデックス への移動


ヘッダーファイル

stdlib.h

カテゴリ

変換ルーチン,メモリおよび文字列操作ルーチン

プロトタイプ

size_t mbstowcs(wchar_t *pwcs, const char *s, size_t n);

説明

マルチバイト文字列を wchar_t 配列に変換します。

この関数は,マルチバイト文字列 s を pwcs が指す配列に変換します。配列に格納される最大文字数は n です。無効なマルチバイトシーケンスが検出された場合,mbstowcs は,(size_t) -1 を返します。

mbstowcs が n を返す場合,pwcs 配列は値 0 で終了しません。

戻り値

無効なマルチバイトシーケンスが検出された場合,mbstowcs は,(size_t) -1 を返します。そうでない場合,この関数は,変更された配列要素の数を返します。終了コード(ある場合)は含まれません。



 #include <stdio.h>
 #include <stdlib.h>
 void main(void)
 {
   int x;
   char    *mbst = (char *)malloc(MB_CUR_MAX);
   wchar_t *pwst = L"Hi";
   wchar_t *pwc      = (wchar_t *)malloc(sizeof( wchar_t));
   printf ("Convert to multibyte string:\n");
   x = wcstombs (mbst, pwst, MB_CUR_MAX);
   printf ("\tCharacters converted %u\n",x);
   printf ("\tHEx value of first");
   printf (" multibyte character: %#.4x\n\n", mbst);
   printf ("Convert back to wide character string:\n");
   x = mbstowcs(pwc, mbst, MB_CUR_MAX);
   printf( "\tCharacters converted: %u\n",x);
   printf( "\tHex value of first");
   printf( "wide character: %#.4x\n\n", pwc);
 }



移植性



POSIX Win32 ANSI C ANSI C++

+

+

+

+