Advertisement
crsiii

itoa

Oct 29th, 2011
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.40 KB | None | 0 0
  1. void itoa(int num, char alpha[])
  2. {
  3.     memset((char*)alpha, 0, 15); // <cstring>
  4.     int log = (floor(log10((double)num)) + 1); // <cmath>
  5.     int done = 0;
  6.     for(int i = log - 1; i >= 0; --i)
  7.     {
  8.         int temp = num;
  9.         int tlog = log - 1;
  10.         for(tlog; tlog > done; tlog--)
  11.         {
  12.             temp = temp % (int)(pow(10, (double)tlog));
  13.         }
  14.         temp /= pow(10, (double)done);
  15.         alpha[i] = temp + '0';
  16.         done++;
  17.     }
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement