int atoi(const char *s)
{
assert(s!=NULL);
int sign=1;
int num=0;
if(*s==' '||*s=='\t')
s++;
if(*s=='-')
{
sign=-1;
s++;
}
while(*s)
{
if(*s>='0'&&*s<='9')
{
num=10*num+*s-'0';
}
else
return num*sign;
s++;
}
return num*sign;
}
int _tmain(int argc, _TCHAR* argv[])
{
char *s=" -23+4";
cout<<atoi(s)<<endl;
return 0;
}
posted on 2012-05-13 15:18
qiushao 阅读(124)
评论(0) 编辑 收藏 引用