2010南非世界杯_世界杯名单 - clywdl.com

atoi, atol, atoll

2025-09-25 00:52:21

C

编译器支持

语言

头文件

类型支持

程序工具

变参函数支持

错误处理

动态内存管理

字符串库

算法

数值

日期和时间工具

输入/输出支持

本地化支持

并发支持 (C11)

技术规范

符号索引

[编辑] 字符串库

空终止字节字符串

空终止多字节字符串

空终止宽字符串

[编辑] 空终止字节字符串

函数

字符操作

isalnum

isalpha

islower

isupper

isdigit

isxdigit

isblank(C99)

iscntrl

isgraph

isspace

isprint

ispunct

tolower

toupper

与数字格式相互转换

atoiatolatoll(C99)

atof

strtolstrtoll(C99)

strtoulstrtoull(C99)

strtoimaxstrtoumax(C99)(C99)

strtofstrtodstrtold(C99)(C99)

strfromfstrfromdstrfroml(C23)(C23)(C23)

字符串操作

strcpystrcpy_s(C11)

strncpystrncpy_s(C11)

strcatstrcat_s(C11)

strncatstrncat_s(C11)

strxfrm

strdup(C23)

strndup(C23)

字符串检查

strlenstrnlen_s(C11)

strcmp

strncmp

strcoll

strchr

strrchr

strspn

strcspn

strpbrk

strstr

strtokstrtok_s(C11)

内存操作

memchr

memcmp

memsetmemset_explicitmemset_s(C23)(C11)

memcpymemcpy_s(C11)

memmovememmove_s(C11)

memccpy(C23)

杂项

strerrorstrerror_sstrerrorlen_s(C11)(C11)

[编辑]

在头文件 中定义

int atoi ( const char* str );

(1)

long atol ( const char* str );

(2)

long long atoll( const char* str );

(3)

(C99 起)

解释由 str 指向的字节字符串中的整数值。隐含的基数总是 10。

丢弃所有空白字符,直到找到第一个非空白字符,然后尽可能多地获取字符以形成有效的整数数字表示,并将其转换为整数值。有效的整数值包含以下部分

(可选) 加号或减号数字

如果结果的值不能表示,即转换后的值超出相应返回类型的范围,则行为未定义。

目录

1 参数

2 返回值

3 注意

4 示例

5 引用

6 参阅

[编辑] 参数

str

-

指向要解释的空终止字节字符串的指针

[编辑] 返回值

成功时,返回对应于 str 内容的整数值。

如果无法执行转换,则返回 ​0​。

[编辑] 注意

名称代表“ASCII to integer”(ASCII 到整数)。

[编辑] 示例

运行此代码

#include

#include

int main(void)

{

printf("%i\n", atoi(" -123junk"));

printf("%i\n", atoi(" +321dust"));

printf("%i\n", atoi("0"));

printf("%i\n", atoi("0042")); // treated as a decimal number with leading zeros

printf("%i\n", atoi("0x2A")); // only leading zero is converted discarding "x2A"

printf("%i\n", atoi("junk")); // no conversion can be performed

printf("%i\n", atoi("2147483648")); // UB: out of range of int

}

可能的输出

-123

321

0

42

0

0

-2147483648

[编辑] 参考

C23 标准 (ISO/IEC 9899:2024)

7.22.1.2 The atoi, atol, and atoll functions (p: TBD)

C17 标准 (ISO/IEC 9899:2018)

7.22.1.2 The atoi, atol, and atoll functions (p: 249)

C11 标准 (ISO/IEC 9899:2011)

7.22.1.2 The atoi, atol, and atoll functions (p: 341)

C99 标准 (ISO/IEC 9899:1999)

7.20.1.2 The atoi, atol, and atoll functions (p: 307)

C89/C90 标准 (ISO/IEC 9899:1990)

4.10.1.2 The atoi function

4.10.1.3 The atol function

[编辑] 另请参阅

strtolstrtoll(C99)

将字节字符串转换为整数值 (函数) [编辑]

strtoul strtoull(C99)

将字节字符串转换为无符号整数值 (函数) [编辑]

wcstolwcstoll(C95)(C99)

将宽字符串转换为整数值 (函数) [编辑]

wcstoulwcstoull(C95)(C99)

将宽字符串转换为无符号整数值 (函数) [编辑]

C++ documentation for atoi, atol, atoll

虎扑怎么发私信 虎扑体育发私信图文教程 「梦幻西游」155女儿村能秒多少