wctob
From cppreference.net
|
헤더 파일에 정의됨
<wchar.h>
|
||
|
int
wctob
(
wint_t c
)
;
|
(C95부터) | |
와이드 문자
c
의 초기 변환 상태에서 멀티바이트 문자 변환이 단일 바이트인 경우 좁힙니다.
이는 일반적으로 ASCII 문자 집합의 문자들에 대해 가능합니다. 왜냐하면 대부분의 멀티바이트 인코딩(UTF-8과 같은)은 이러한 문자들을 인코딩하기 위해 단일 바이트를 사용하기 때문입니다.
목차 |
매개변수
| c | - | 와이드 문자를 좁은 문자로 변환 |
반환값
EOF
만약
c
가 초기 시프트 상태에서 길이가
1
인 멀티바이트 문자를 나타내지 않는 경우.
그렇지 않으면,
c
의 싱글바이트 표현을
unsigned
char
로 변환한 후
int
로 변환한 값
예제
이 코드 실행
#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