home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_100 / 161_01 / 508.c < prev    next >
C/C++ Source or Header  |  1985-08-29  |  539b  |  32 lines

  1. #include "timer1.h"
  2.  
  3.     long value = 1<<25 - 1;
  4.     char buf[30];
  5.     DO_STMT("Long to ASCII using MAXINT")    ltoa(value, buf)    OD
  6. }
  7.     
  8. /* largest (normal length) positive integer */
  9. # define MAXINT 32767
  10.  
  11. /*
  12.  *    convert a positive long integer into
  13.  *    a sequence of ASCII digits (decimal)
  14.  */
  15.  
  16. ltoa(value, buf)
  17. long value;
  18. char *buf;
  19. {
  20.     int svalue;
  21.  
  22.     while (value > MAXINT) {
  23.         *buf++ = (int)(value % 10) + '0';
  24.         value /= 10;
  25.     }
  26.     svalue = value;
  27.     while (svalue > 0) {
  28.         *buf++ = svalue % 10 + '0';
  29.         svalue /= 10;
  30.     }
  31. }
  32.