atoi的实现
需要注意:
1.正负数
2.字符串是否有效
3.字符串是否溢出(此处省略)
1 /*************************************************************************
2 > File Name: my_atoi.c
3 > Author: ChenPeng
4 > Mail:479103815@qq.com
5 > Blog: http://www.cnblogs.com/cpsmile/
6 > Created Time: Fri 03 Apr 2015 06:34:34 PM CST
7 ************************************************************************/
8 #include<stdio.h>
9 #include<stdlib.h>
10
11 /* 将字符串转数字换为对应的整数*/
12 int my_atoi(char *str)
13 {
14 int isPos = 1; //记录是否是正数,1表示正数,否则是负数
15 int sum = 0;
16 if(*str == '-')
17 {
18 isPos = 0;//为负数
19 ++str;
20 }
21 while(*str != '