home *** CD-ROM | disk | FTP | other *** search
/ Atari FTP / ATARI_FTP_0693.zip / ATARI_FTP_0693 / Mint / mntlib25.zoo / ltoa.c < prev    next >
C/C++ Source or Header  |  1992-09-05  |  893b  |  54 lines

  1. #include <string.h>
  2. #include "lib.h"
  3. #include "lib.h"
  4.  
  5. #ifdef __STRICT_ANSI__
  6. #  ifdef __STDC__
  7.     char * strrev(char *);
  8. #  else
  9.     extern char * strrev();
  10. #  endif
  11. #endif
  12.  
  13. char    _numstr[] = "0123456789ABCDEF";
  14.  
  15. char *_ultoa(n, buffer, radix)
  16.     register unsigned long n;
  17.     register char *buffer;
  18.     register int radix;
  19.     {
  20.     register char *p = buffer;
  21.  
  22.     do
  23.         {
  24.         *p++ = _numstr[n % radix];    /* grab each digit */
  25.         }
  26.         while((n /= radix) > 0);
  27.     *p = '\0';
  28.     return(strrev(buffer));            /* reverse and return it */
  29.     }
  30.  
  31. char *_ltoa(n, buffer, radix)
  32.     register long n;
  33.     register char *buffer;
  34.     int radix;
  35.     {
  36.     register char *p = buffer;
  37.  
  38.     if (n < 0)
  39.         {
  40.         *p++ = '-';
  41.         n = -n;
  42.         }
  43.       _ultoa(n, p, radix);
  44.     return(buffer);
  45.     }
  46.  
  47. char *_itoa(n, buffer, radix)
  48.     int n;
  49.     char *buffer;
  50.     int radix;
  51.     {
  52.          return(_ltoa(((long) n), buffer, radix));
  53.     }
  54.