zoukankan
html css js c++ java
atoi 函数实现
要考虑的东西实在也挺多的。总结如下:
1 前面空格分隔符号的时候
2 第一个符号位处理+ -
3 遇到非数字字符退出
4 为正数的时候,大于INT_MAX上溢
5 为负数的时候, 小于INT_MIN下溢
6 为空字符串或者空指针的时候
1
int
atoi(
const
char
*
str)
2
{
3
if
(str == nullptr)
return
0
;
4
//
注意:判断空字符串数组
5
if
(*str ==
'