atol, _atol_l, _wtol, _wtol_l

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

long atol(
   const char *str 
);
long _atol_l(
   const char *str,
   _locale_t locale
);
long _wtol(
   const wchar_t *str 
);
long _wtol_l(
   const wchar_t *str,
   _locale_t locale
);

매개 변수

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

  • locale
    사용 하는 로캘.

반환 값

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

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

설명

이 함수는 정수 (long) 값으로 문자열 변환 (atol).

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

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

[whitespace] [sign] [digits]]

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

_wtol동일 atol 와이드 문자열이 사용을 제외 하 고.

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

일반 텍스트 루틴 매핑

TCHAR입니다.H 루틴

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

_Mbcs가 정의

_Unicode가 정의

_tstol

atol

atol

_wtol

_ttol

atol

atol

_wtol

요구 사항

루틴

필수 헤더

atol

<stdlib.h>

_atol_l, _wtol, _wtol_l

<stdlib.h> 및 <wchar.h>

예제

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

// crt_atol.c
// This program shows how numbers stored as
// strings can be converted to numeric values
// using the atol functions.
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>

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

    // An example of the atol function
    // with leading and trailing white spaces.
    str = "  -2309 ";
    value = atol( str );
    printf( "Function: atol( \"%s\" ) = %d\n", str, value );

    // Another example of the atol function 
    // with an arbitrary decimal point.
    str = "314127.64";
    value = atol( str );
    printf( "Function: atol( \"%s\" ) = %d\n", str, value );

    // Another example of the atol function
    // with an overflow condition occurring.
    str = "3336402735171707160320";
    value = atol( str );
    printf( "Function: atol( \"%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