将字符串转为数字
2009-10-09 15:39 Iron 阅读(189) 评论(0) 编辑 收藏 举报#include <cstdio>
#include <cassert>
int atoi(const char* str)
{
assert(str!=NULL);
const char* s = str;
int value=0;
while(*s!=\'\0\')
{
value *= 10;
value += *s - \'0\';
s++;
}
return value;
}
int main()
{
printf("%d\n",atoi("1234"));
}