// a2i.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
bool isDigit(char c);
//输入一个字符串,输出长型整数。
long atol(char *str){
char *p = str;
long l=1,m=0;
if (*p=='-')
{
l=-1;
++p;
}
while(isDigit(*p))
{
m = m*10 + (*p-'0');
++p;
}
if(!*p)
return m*l;
else
return -100;
}
int main(int argc, char* argv[])
{
long l=atol("12345");
printf("%ld!\n",l);
return 0;
}
bool isDigit(char c)
{
return (c>='0')&&(c<='9');
}
字符串转长型整数
最新推荐文章于 2023-05-28 18:15:09 发布