다음을 통해 공유


mbtowc, _mbtowc_l

멀티 바이트 문자를 해당 와이드 문자로 변환합니다.

int mbtowc(
   wchar_t *wchar,
   const char *mbchar,
   size_t count 
);
int _mbtowc_l(
   wchar_t *wchar,
   const char *mbchar,
   size_t count,
   _locale_t locale
);

매개 변수

  • wchar
    와이드 문자 주소 (wchar_t 형식).

  • mbchar
    바이트들의 시퀀스 주소(멀티바이트 문자).

  • count
    확인하는 바이트 수입니다.

  • 로캘(locale)
    사용할 로캘입니다.

반환 값

mbcharNULL 이 아니고 mbchar 이 가리키는 개체가 유효한 멀티바이트 문자를 형성할 경우, mbtowc 는 멀티 바이트 문자의 바이트로 길이를 반환 합니다. mbchar 이 NULL 이거나 또는 이것이 가리키는 개체가 와이드 null 문자 (L'\0') 일 경우, 함수는 0을 반환 합니다. mbchar 이 가리키는 개체가 첫 count 문자 내부에 유효한 멀티 바이트 문자를 형성하지 않는 경우, 이것은 -1을 반환합니다.

설명

만일 mbchar 는 NULL 이고, 해당 와이드 문자인 경우, mbtowc 함수는 count 를 변환하거나 mbchar 에 의해 지정된 적은 바이트들을 변환합니다. 만일 wcharNULL이 아닌경우, mbtowcwchar에서 결과 와이드 문자는 저장합니다. mbtowcMB_CUR_MAX 바이트 이상을 조사하지 않습니다. mbtowc 은 로캘 종속 동작으로 현재 로캘을 사용합니다. _mbtowc_l 은 전달된 로캘을 사용하는 것을 제외하곤 동일 합니다. 자세한 내용은 로캘을 참조하십시오.

요구 사항

루틴

필수 헤더

mbtowc

<stdlib.h>

_mbtowc_l

<stdlib.h>

호환성에 대한 자세한 내용은 소개 단원의 호환성 부분을 참조하십시오.

라이브러리

모든 버전의 C 런타임 라이브러리입니다.

예제

// crt_mbtowc.c
/* Illustrates the behavior of the mbtowc function
 */

#include <stdlib.h>
#include <stdio.h>

int main( void )
{
    int      i;
    char    *pmbc    = (char *)malloc( sizeof( char ) );
    wchar_t  wc      = L'a';
    wchar_t *pwcnull = NULL;
    wchar_t *pwc     = (wchar_t *)malloc( sizeof( wchar_t ) );
    printf( "Convert a wide character to multibyte character:\n" );
    wctomb_s( &i, pmbc, sizeof(char), wc );
    printf( "  Characters converted: %u\n", i );
    printf( "  Multibyte character: %x\n\n", *pmbc );

    printf( "Convert multibyte character back to a wide "
            "character:\n" );
    i = mbtowc( pwc, pmbc, MB_CUR_MAX );
    printf( "  Bytes converted: %u\n", i );
    printf( "  Wide character: %x\n\n", *pwc );
    printf( "Attempt to convert when target is NULL\n" );
    printf( "  returns the length of the multibyte character:\n" );
    i = mbtowc( pwcnull, pmbc, MB_CUR_MAX );
    printf( "  Length of multibyte character: %u\n\n", i );

    printf( "Attempt to convert a NULL pointer to a" );
    printf( " wide character:\n" );
    pmbc = NULL;
    i = mbtowc( pwc, pmbc, MB_CUR_MAX );
    printf( "  Bytes converted: %u\n", i );
}

Output

Convert a wide character to multibyte character:
  Characters converted: 1
  Multibyte character: 61

Convert multibyte character back to a wide character:
  Bytes converted: 1
  Wide character: 61

Attempt to convert when target is NULL
  returns the length of the multibyte character:
  Length of multibyte character: 1

Attempt to convert a NULL pointer to a wide character:
  Bytes converted: 0

해당 .NET Framework 항목

해당 사항 없음. 표준 C 함수를 호출하려면 PInvoke를 사용합니다. 자세한 내용은 플랫폼 호출 예제를 참조하십시오.

참고 항목

참조

데이터 변환

MultiByteToWideChar

로캘

멀티바이트 문자 시퀀스 해석

_mbclen, mblen, _mblen_l

wcstombs, _wcstombs_l

wctomb, _wctomb_l