atoi

Section: C Library Functions (3)
Updated: 2026-02-08
Index JM Home Page roff page
 

名前

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

ライブラリ

標準 C ライブラリ (libc,~-lc)  

書式

#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 <= 2.19: */ _BSD_SOURCE || _SVID_SOURCE
 

説明

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

strtol(nptr, NULL, 10);

と同じである。

The atol() and atoll() functions behave the same as atoi(), except that they convert the initial portion of the string to their return type of long or long~long.  

返り値

The converted value or 0 on error.  

属性

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

バージョン

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

標準規格

C11, POSIX.1-2008.  

歴史

C99, POSIX.1-2001, SVr4, 4.3BSD.

C89 and POSIX.1-1996 include the functions atoi() and atol() only.  

バグ

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)


 

Index

名前
ライブラリ
書式
説明
返り値
属性
バージョン
標準規格
歴史
バグ
関連項目

This document was created by man2html, using the manual pages.