atoi(3)

文字列を整数型に変換する · man3 · 日本語

ATOI(3) Linux Programmer's Manual ATOI(3)

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)EN を参照。

インターフェース 属性 値
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/ に書かれている。

2020-08-13 GNU