Advertisement
rockdrilla

itoa_krd()

Jul 1st, 2017
471
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.36 KB | None | 0 0
  1. void itoa_krd(const int & val, char *buf) {
  2.     char t0[sizeof(int) * 4] = {};
  3.     char *s = buf, *t = t0 + sizeof(t0) - 2;
  4.     std::div_t qr;
  5.  
  6.     qr.quot = val;
  7.     do {
  8.         qr = std::div(qr.quot, 10);
  9.         *(t--) = '0' + qr.rem;
  10.     } while ((qr.quot != 0) || (qr.quot != 0));
  11.     t++;
  12.  
  13.     do {
  14.         *(s++) = *(t++);
  15.     } while (*t);
  16. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement