home *** CD-ROM | disk | FTP | other *** search
- /*----------------------------------------------------------------------------
- * itoa() : Integer to ascii conversion program.
- * (This program is from p. 60 of the Kernighan and Ritchie text)
- *---------------------------------------------------------------------------*/
-
- #include "cbtree.h"
-
- void bt_itoa(n, s) /* CBTREE version so it doesn't collide with Turbo Lib */
- int n;
- char s[];
- {
- extern void reverse();
- int i, sign;
-
- if ((sign = n) < 0) /* record sign */
- n = -n; /* make n positive */
- i = 0;
- do { /* generate digits in reverse order */
- s[i++] = n % 10 + '0'; /* get next digit */
- } while ((n /= 10) > 0); /* delete it */
-
- if (sign < 0)
- s[i++] = '-';
- s[i] = '\0';
-
- reverse(s);
- }
-
- /* (This program is from p. 59 of the Kernighan and Ritchie text)
- */
- void reverse(s) /* reverse string s in place */
- char s[];
- {
- extern int strlen();
- int c, i, j;
-
- for (i = 0, j = strlen(s)-1; i <j; i++, j--) {
- c = s[i];
- s[i] = s[j];
- s[j] = c;
- }
- }
-