int atoi( char* pStr ) { int iRetVal = 0; if (pStr) { while ( *pStr && *pStr <= '9' && *pStr >= '0' ) { iRetVal = (iRetVal * 10) + (*pStr - '0'); pStr++; } } return iRetVal; } If we allow -ve and + signs we need to take care of them as well in the out put and check for invalid characters.
No comments:
Post a Comment