/*************************************************************************
> File Name: Atoi.c
> Author: qinchao
> Created Date:2018-01-28 Time:04:36:18.
************************************************************************/
// 32bits无符号整数表示范围[0, 2^32-1]
// 32bits有符号整数表示范围为[-2^31, 2^31-1]
int Atoi(const char *str) {
unsigned int value = 0;
// 1表示负数,0表示整数
int negative = 0;
//判断str指针非NULL
if (str != NULL) {
//判断是否为负数
if (str[0] == '-') {
negative = 1;
str++;
}
else if (str[0] == '+') {
str++;
}
// str指向的字符串以0结尾
while (str[0] != '
近期评论