home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / me34src.zip / me3 / util / tobase.c < prev    next >
C/C++ Source or Header  |  1995-01-14  |  427b  |  26 lines

  1. /* tobase(x,base): convert x to base
  2.     see also todec()
  3.     Craig Durland    Public Domain
  4. */
  5.  
  6. #define TRUE 1
  7. #define FALSE 0
  8.  
  9. char *tobase(x,base) long x; int base;
  10. {
  11.   static char str[40];
  12.   char *ptr = &str[39];
  13.   int minus = FALSE, z;
  14.  
  15.   *ptr = '\0';
  16.   if (x < 0) { minus = TRUE; x = -x; }
  17.   do
  18.   {
  19.     if ((z = x % base)>9) z += 7;
  20.     *--ptr = z +'0';
  21.     x /= base;
  22.   } while (x>0);
  23.   if (minus) *--ptr = '-';
  24.   return(ptr);
  25. }
  26.