sourCEntral - mobile manpages

pdf

ATOI

名前

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() と同様の振る舞いをするが、 文字列のはじめの部分をそれぞれ longlong long に変換する。

返り値

The converted value or 0 on error.

属性

この節で使用されている用語の説明については、 attributes(7) を参照。

img

準拠

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/ に書かれている。

pdf