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

  1. /* i_to_a.c:  Convert an integer to a string.
  2.  * The string is stored in this routine so it will be overwritten every time
  3.  *   the routine is called.
  4.  * C Durland    Public Domain
  5.  */
  6.  
  7. #include "const.h"
  8.  
  9. char *i_to_a(n) int n;
  10. {
  11.   static char str[DIGITS_PER_INT(sizeof(int)) + 1];
  12.  
  13.   register char *ptr = &str[DIGITS_PER_INT(sizeof(int))];
  14.   int minus = FALSE;
  15.   register unsigned int x = n;
  16.  
  17.   if (n < 0) { minus = TRUE; x = -n; }
  18.   *ptr = '\0';
  19.   do { *(--ptr) = (x % 10) +'0'; x /= 10; } while (x>0);
  20.   if (minus) *(--ptr) = '-';
  21.   return ptr;
  22. }
  23.