wctob
提供: cppreference.com
<tbody>
</tbody>
| ヘッダ <wchar.h> で定義
|
||
int wctob( wint_t c ); |
(C95以上) | |
初期状態における同等なマルチバイト文字がシングルバイトであれば、ワイド文字 c をナロー化します。
これは一般的には ASCII 文字集合の文字に対して可能です。 ほとんどのマルチバイトエンコーディング (UTF-8 など) はこれらの文字のエンコードにシングルバイトを使用します。
引数
| c | - | ナロー化するワイド文字 |
戻り値
c が初期シフト状態において長さ 1 のマルチバイト文字を表さない場合は EOF。
そうでなければ、 unsigned char としての c の int に変換されたシングルバイト表現。
例
Run this code
#include <locale.h>
#include <wchar.h>
#include <stdio.h>
#include <assert.h>
void try_narrowing(wchar_t c)
{
int cn = wctob(c);
if(cn != EOF)
printf("%#x narrowed to %#x\n", c, cn);
else
printf("%#x could not be narrowed\n", c);
}
int main(void)
{
char* utf_locale_present = setlocale(LC_ALL, "th_TH.utf8");
assert(utf_locale_present);
puts("In Thai UTF-8 locale:");
try_narrowing(L'a');
try_narrowing(L'๛');
char* tis_locale_present = setlocale(LC_ALL, "th_TH.tis620");
assert(tis_locale_present);
puts("In Thai TIS-620 locale:");
try_narrowing(L'a');
try_narrowing(L'๛');
}
出力例:
In Thai UTF-8 locale:
0x61 narrowed to 0x61
0xe5b could not be narrowed
In Thai TIS-620 locale:
0x61 narrowed to 0x61
0xe5b narrowed to 0xfb