字符串转长型整数

来源:互联网 发布:农村淘宝合伙人报名 编辑:程序博客网 时间:2024/05/18 03:29
// 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');}

原创粉丝点击