home *** CD-ROM | disk | FTP | other *** search
/ Nebula 2 / Nebula Two.iso / Apps / ScreenSavers / BackSpaceViews / SpiralView.BackModule / Source / alphanum.m < prev    next >
Encoding:
Text File  |  1996-01-24  |  684 b   |  37 lines

  1. //**** Alpha Numeric functions
  2.  
  3. #import <string.h>
  4. #import "alphanum.h"
  5.  
  6. //* itoa: convert num to characters in str
  7. void itoa(int num, char str[])
  8. {
  9.     int index, sign;
  10.  
  11.     if ((sign = num) < 0)    //** record sign
  12.         num = -num;            //** make num positive
  13.  
  14.     index = 0;
  15.     do {        //** generate digits in reverse order
  16.         str[index++] = num % 10 + '0';    //** get next digit
  17.     } while ((num /= 10) > 0);        //** delete it
  18.  
  19.     if (sign < 0)
  20.         str[index++] = '-';
  21.     str[index] = '\0';
  22.  
  23.     reverse(str);
  24. }
  25.  
  26. //** reverse: reverse string str in place
  27. void reverse(char str[])
  28. {
  29.     int c, index, j;
  30.  
  31.     for (index=0, j=strlen(str)-1; index<j; index++, j--) {
  32.         c = str[index];
  33.         str[index] = str[j];
  34.         str[j] = c;
  35.     }
  36. }
  37.