Namespaces
Variants

btowc

From cppreference.net
헤더 파일에 정의됨 <wchar.h>
wint_t btowc ( int c ) ;
(C95부터)

단일 바이트 문자 c 를 ( unsigned char 로 재해석됨) 해당 와이드 문자 등가물로 확장합니다.

대부분의 멀티바이트 문자 인코딩은 ASCII 문자 집합의 문자들을 표현하기 위해 싱글바이트 코드를 사용합니다. 이 함수는 그러한 문자들을 wchar_t 로 변환하는 데 사용될 수 있습니다.

목차

매개변수

c - 확장할 단일 바이트 문자

반환값

WEOF 만약 c 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

참고문헌

  • C11 표준 (ISO/IEC 9899:2011):
  • 7.29.6.1.1 btowc 함수 (p: 441)
  • C99 표준 (ISO/IEC 9899:1999):
  • 7.24.6.1.1 btowc 함수 (p: 387)

참조 항목

(C95)
가능한 경우 와이드 문자를 단일 바이트 좁은 문자로 축소합니다
(함수)
C++ 문서 for btowc