c - 为什么我不应该使用 atoi()?

标签 c

<分区>

有人告诉我不应该使用 atoi() ,而且我应该始终使用 strtol()反而。 atoi() 有什么问题我不应该使用它? strtol() 真的是正确的选择吗? (关于 strtol() 返回一个 long 而不是像 atoi() 那样的 int 的事实呢? ?)

最佳答案

来自您自己的 link :

The atoi() function is subsumed by strtol() but is retained because it is used extensively in existing code. If the number is not known to be in range, strtol() should be used because atoi() is not required to perform any error checking.

或者

atoi 已过时

关于c - 为什么我不应该使用 atoi()?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17710018/

相关文章:

c - 在 netbeans C 中使用 header

c - AES 192、AES-256 的段错误,不适用于 AES-128 位

c - 信号 11 (SIGSEGV)

c - 第二次调用 GetOpenFileName 在 Win 8.1 64 位机器上无错误地崩溃

c - 如何动态居中对齐 char * 字符串中的文本以适应 C 中总共 16 个空格?

c++ - 编译要在 C++ 版本中链接的 C 库...是否需要指定 C++ 标准?

c - 在C中合并两个文件

c - C 中参数数量未知的函数

c - 如果 pthread_cond_wait 不是原子的会发生什么?

const char array[] = {set} 以大端存储,我需要小端