btowc
|
定義先ヘッダ
<wchar.h>
|
||
|
wint_t btowc
(
int
c
)
;
|
(C95以降) | |
単一バイト文字
c
を(
unsigned
char
として再解釈して)ワイド文字に変換します。
ほとんどのマルチバイト文字エンコーディングは、ASCII文字セットの文字を表現するためにシングルバイトコードを使用します。この関数は、そのような文字を wchar_t に変換するために使用できます。
目次 |
パラメータ
| c | - | ワイド文字に変換するシングルバイト文字 |
戻り値
WEOF
if
c
is
EOF
c
のワイド文字表現。
(
unsigned
char
)
c
が初期シフト状態において有効な単一バイト文字である場合、それ以外の場合は
WEOF
。
例
#include <stdio.h> #include <wchar.h> #include <locale.h> #include <assert.h> void try_widen(unsigned char c) { wint_t w = btowc(c); if(w != WEOF) printf("The single-byte character %#x widens to %#x\n", c, w); else printf("The single-byte character %#x failed to widen\n", c); } int main(void) { char *loc = setlocale(LC_ALL, "lt_LT.iso88594"); assert(loc); printf("In Lithuanian ISO-8859-4 locale:\n"); try_widen('A'); try_widen('\xdf'); // German letter ß (U+00df) in ISO-8859-4 try_widen('\xf9'); // Lithuanian letter ų (U+0173) in ISO-8859-4 setlocale(LC_ALL, "lt_LT.utf8"); printf("In Lithuanian UTF-8 locale:\n"); try_widen('A'); try_widen('\xdf'); try_widen('\xf9'); }
出力例:
In Lithuanian ISO-8859-4 locale: The single-byte character 0x41 widens to 0x41 The single-byte character 0xdf widens to 0xdf The single-byte character 0xf9 widens to 0x173 In Lithuanian UTF-8 locale: The single-byte character 0x41 widens to 0x41 The single-byte character 0xdf failed to widen The single-byte character 0xf9 failed to widen