Note the problem:
1) The case that the string is a null pointer.
2) Assume that the input is an empty string ""
3) are all characters outside the ' 0 ' to ' 9 ' illegal? The plus and minus signs are legal inputs.
4) Consider overflow
#include <iostream>using namespace Std;bool g_value=false;int atoi (char * number) {if (number = = NULL | | *number = = ' + ') {G_value=true;return 0;} Double count=0;//here is a double type bool Min=false;if (*number== '-') {min=true;number++;} else if (' + ' ==*number) {min=false;number++;} Elsemin=false;while (* (number) = ' \ ") {if ((*number-' 0 ') >=0&& (*number-' 0 ') <=9) {count = count*10 + (* number-' 0 '); if (false==min&&count> 0x7FFFFFFF | | true==min&&count< (signed int) 0x80000000) {cout<< "Overflow" <<endl;count=0; break;} number++;} else{break;}} if (min) count*=-1;return (int) count;} int main () {char * number= " -11111"; cout<<atoi (number); return 0;}
watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqvynv5aw5nzmvpodg4oa==/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma== /dissolve/70/gravity/center ">
Memmove and memcpy differences and implementations: http://www.cnblogs.com/foxinhongyan/articles/1267624.html
Convert a string to an integer