atol,_wtol
stdlib.h:インデックス への移動
ヘッダーファイル
stdlib.h
カテゴリ
変換ルーチン,演算ルーチン
プロトタイプ
long atol(const char *s);
long _wtol(const wchar_t *s);
説明
文字列を long に変換します。
- atol は,s が指す文字列を long に変換します。atol は,次の表現をこの順序で認識します。
- タブとスペースからなるオプションの文字列
- オプションの符号
- 数字からなる文字列
文字列は,次の一般形に一致する必要があります。
[ws] [sn] [ddd]
この関数は,最初の認識されない文字で変換を終了します。atol には,オーバーフローに備えた機能がありません(結果は未定義)。
戻り値
atol は,入力文字列の変換後の値を返します。文字列を対応する型(long)の数値に変換できない場合,atol は,0 を返します。
例
#include <stdlib.h>
#include <stdio.h>
int main(void)
{
long l;
char *lstr = "98765432";
l = atol(lstr);
printf("string = %s integer = %ld\n", lstr, l);
return(0);
}
移植性
| POSIX | Win32 | ANSI C | ANSI C++ | |
|---|---|---|---|---|
|
atol |
+ |
+ |
+ |
+ |
|
_wtol |
+ |