atoi的实现
#include <iostream> using namespace std; int atoi(char* s) { int retval=0; int n=1; if (*s=='-') { n=-1; s++; } while (*s!='\0') { retval=retval*10+(*s-'0'); s++; } return(n*retval); } void main() { char s[6]; long n; printf("Enter a string:\n") ; gets(s); n = atoi(s); printf("%ld\n",n); while(1); }