Advertisement
Shalfey

Simple atoi()

Apr 19th, 2012
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.29 KB | None | 0 0
  1. int my_atoi(const char*  src)
  2. {
  3.     int result = 0;
  4.     int digit = 1;
  5.     const int DIGIT_DIFFERENCE = 10;
  6.     const char ZERO_SYMBOL = '0';
  7.     for(int i = (strlen(str)-1); i >= 0; i--)
  8.     {
  9.         result = result + (digit * int(str[i]-ZERO_SYMBOL));
  10.         digit = digit * DIGIT_DIFFERENCE;
  11.     }
  12.     return result;
  13. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement