Share via


atoi, _atoi_l, _wtoi, _wtoi_l

문자열을 정수로 변환 합니다.

int atoi(
   const char *str 
);
int _wtoi(
   const wchar_t *str 
);
int _atoi_l(
   const char *str,
   _locale_t locale
);
int _wtoi_l(
   const wchar_t *str,
   _locale_t locale
);

매개 변수

  • str
    변환 될 문자열입니다.

  • locale
    사용 하는 로캘.

반환 값

각 함수는 반환의 int 값에서 입력된 문자를 숫자로 해석 하 여 생성 합니다.반환 값 0에 대 한입니다 atoi_wtoi, 입력 값을 해당 형식으로 변환할 수 없는 경우.

큰 음의 정수 계열 값을 오버플로 경우에 LONG_MIN 이 반환 됩니다.atoi_wtoi 반환 INT_MAX 및 INT_MIN 이러한 조건입니다.모든 범위를 벗어난 경우에 errno 로 설정 된 ERANGE.매개 변수가 전달 된 경우 NULL, 설명에 따라 잘못 된 매개 변수 처리기가 호출 매개 변수 유효성 검사.실행을 계속 수 있으면 이러한 함수를 설정 errno 에 EINVAL 및 0을 반환 합니다.

설명

이러한 함수는 문자열을 정수 값으로 변환 (atoi 및 _wtoi).입력된 문자열의 지정 된 형식의 숫자 값으로 해석 될 수 있는 문자 시퀀스입니다.이 함수는 숫자의 일부로 인식할 수 없는 첫 번째 문자에서 입력된 문자열을 읽는 중지 합니다.이 문자는 null 문자 ('\ 0' 또는 '\ 0' L)는 문자열을 종료 합니다.

str 인수를 atoi_wtoi 형식은 다음과 같습니다.

[whitespace] [sign] [digits]]

A whitespace 는 무시 됩니다; 공백이 나 탭 문자 중 구성 됩니다. sign하나는 더하기 (+) 또는 빼기 (-) 및 digits 하나 이상의 숫자입니다.

버전으로 이러한 함수는 _l 접미사는 현재 로캘 대신 전달 된 로캘 매개 변수를 사용할 경우를 제외 하 고 동일 합니다.자세한 내용은 로캘를 참조하십시오.

일반 텍스트 루틴 매핑

TCHAR입니다.H 루틴

_UNICODE 및 _Mbcs가 정의 되지 않았습니다.

_Mbcs가 정의

_Unicode가 정의

_tstoi

atoi

atoi

_wtoi

_ttoi

atoi

atoi

_wtoi

요구 사항

루틴

필수 헤더

atoi

<stdlib.h>

_atoi_l, _wtoi, _wtoi_l

<stdlib.h> 또는 <wchar.h>

예제

이 프로그램이 어떻게 사용 하 여 숫자 값을 문자열로 저장 된 숫자를 변환할 수 있습니다 보여 줍니다 있는 atoi 함수입니다.

// crt_atoi.c
// This program shows how numbers 
// stored as strings can be converted to
// numeric values using the atoi functions.

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

int main( void )
{
    char    *str = NULL;
    int     value = 0;

    // An example of the atoi function.
    str = "  -2309 ";
    value = atoi( str );
    printf( "Function: atoi( \"%s\" ) = %d\n", str, value );

    // Another example of the atoi function.
    str = "31412764";
    value = atoi( str );
    printf( "Function: atoi( \"%s\" ) = %d\n", str, value );

    // Another example of the atoi function 
    // with an overflow condition occuring.
    str = "3336402735171707160320";
    value = atoi( str );
    printf( "Function: atoi( \"%s\" ) = %d\n", str, value );
    if (errno == ERANGE)
    {
       printf("Overflow condition occurred.\n");
    }
}
  

해당 .NET Framework 항목

참고 항목

참조

데이터 변환

부동 소수점 지원

로캘

_ecvt

_fcvt

_gcvt

setlocale을 _wsetlocale

_atodbl, _atodbl_l, _atoldbl, _atoldbl_l, _atoflt _atoflt_l