次の方法で共有


atol、_atol_l、_wtol、_wtol_l

長整数を文字列に変換します。

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 の値が入力文字の数として解釈によって生成された関数はを返します。戻り値は入力がその型の値に変換できない場合はatol の 0L です。

大きい正の整数値を使用してオーバーフローの場合はを返します atolLONG_MAX; 大きい負の整数値でオーバーフローの場合LONG_MIN が返されます。すべての範囲の場合errno は ERANGE に設定されます。渡されるパラメーターが NULL いるように無効なパラメーター ハンドラーが パラメーターの検証 に説明されているように開始されます。実行の継続が許可 EINVAL し0 に設定する errno 関数。

解説

これらの関数は長整数値 () に atol 文字列をに変換します。

入力文字列は指定した型の数値として解釈できる文字のシーケンスです。関数は数値の一部として認識できない最初の文字の入力文字列の読み取りを停止します。この文字列は文字を終了する NULL の文字 (「 \ 0 " または L \ 0 ") である場合があります。

atol への str の引数に次のフォームがあります :

[whitespace] [sign] [digits]]

whitespace 空間はタブ文字で無視される構成されています ; sign は(+) または負符号 (-)。; と digits は一つ以上の数字です。

_wtolatol と同じですがワイド文字列を使用します。

_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