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

関連キーワード

atoi, ATOI, long, nptr, atoll, atol, 関数, SOURCE, バグ, 属性

Linux マニュアル 一覧

[man1] [man2] [man3] [man4] [man5] [man6] [man7] [man8]
[a] [b] [c] [d] [e] [f] [g] [h] [i] [j] [k] [l] [m] [n] [o] [p] [q] [r] [s] [t] [u] [v] [w] [x] [y] [z]

 

Index

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

This document was created by man2html, using the manual pages.
Time: 12:08:35 GMT, June 11, 2022