#include<stdio.h>longintmy_atoi(constchar*nptr){int c;/* current char */longint total;/* current total */int sign;/* if '-', then negative, otherwise positive *//* skip whitespace */while((*nptr ==' ')||(*nptr =='\r')||(*nptr =='\n')||(*nptr =='\v')||(*nptr =='\f')||(*nptr =='\t')){++nptr;}
c =*nptr++;
sign = c;/* save sign indication */if(c =='-'|| c =='+')
c =*nptr++;/* skip sign */
total =0;while((c >='0')&&(c <='9')){
total =10* total +(c -'0');/* accumulate digit */
c =*nptr++;/* get next char */}if(sign =='-')return-total;elsereturn total;/* return result, negated if necessary */}intmain(){char buf1[]="0123456789";printf("buf1 = %ld \r\n",my_atoi(buf1));char buf2[]="-9876543210";printf("buf2 = %ld \r\n",my_atoi(buf2));return0;}