ATOI

Section: Linux Programmer's Manual (3)
Updated: 2020-08-13
Index JM Home Page
 

名前

atoi, atol, atoll - 文字列を整数型に変換する  

書式

#include <stdlib.h>

int atoi(const char *nptr);
long atol(const char *nptr);
long long atoll(const char *nptr);

glibc 向けの機能検査マクロの要件 (feature_test_macros(7) 参照):

atoll():

_ISOC99_SOURCE ||
    || /* Glibc versions <= 2.19: */ _BSD_SOURCE || _SVID_SOURCE
 

説明

atoi() 関数は、nptr によって指示される文字列のはじめの部分を int 型整数に変換する。 この振る舞いは、 atoi() 関数がエラーを見つけない点以外は、

strtol(nptr, NULL, 10);

と同じである。

atol() 関数と atoll() 関数は atoi() と同様の振る舞いをするが、 文字列のはじめの部分をそれぞれ long や long long に変換する。  

返り値

The converted value or 0 on error.  

属性

この節で使用されている用語の説明については、 attributes(7) を参照。
インターフェース 属性 値
atoi(), atol(), atoll() Thread safety MT-Safe locale
 

準拠

POSIX.1-2001, POSIX.1-2008, C99, SVr4, 4.3BSD. C89 と POSIX.1-1996 には atoi() と atol() だけが含まれている。  

注意

POSIX.1 leaves the return value of atoi() on error unspecified. On glibc, musl libc, and uClibc, 0 is returned on error.  

バグ

errno is not set on error so there is no way to distinguish between 0 as an error and as the converted value. No checks for overflow or underflow are done. Only base-10 input can be converted. It is recommended to instead use the strtol() and strtoul() family of functions in new programs.  

関連項目

atof(3), strtod(3), strtol(3), strtoul(3)  

この文書について

この man ページは Linux man-pages プロジェクトのリリース 5.10 の一部である。プロジェクトの説明とバグ報告に関する情報は https://www.kernel.org/doc/man-pages/ に書かれている。

関連キーワード

converted   atoi   atol   atoll   long   整数型   stdlib   検査   マクロ   要件   macros   versions   指示   整数   strtol   nptr   用語   allbox   インターフェース   属性   Thread   safety   locale   leaves   return

Linux マニュアル 一覧

関連するコマンド・関数

atol.3   atoll.3   atoq.3   atof.3   a64l.3   l64a.3
 

Index

名前
書式
説明
返り値
属性
準拠
注意
バグ
関連項目
この文書について

This document was created by man2html, using the manual pages.
Time: 04:39:31 GMT, October 11, 2026