home *** CD-ROM | disk | FTP | other *** search
- /* itoa - convert integer to string */
- /* Version 1.1 1982/11/15 22:30 */
- /* Kernighan, Brian W. & Ritchie, Dennis M.
- "The C Programming Language", Prentice-Hall,
- Englewood Cliffs, NJ, 1978, p. 59-60 */
-
- #ifdef MAINLY
- #else
- #include "c80def.h"
- #endif
-
- #ifdef UNIX
- char *
- #endif
- itoa(n, s) /* convert n to characters in s,
- return s */
- int n;
- char *s;
- {
- register int i;
- register Boolean neg;
- char *t;
- static char Version[]= "Version 1.1 1982/11/15 22:30";
- neg= n < 0; t= s;
- do {
- *s++= abs(n % 10) + '0';
- } while ((n/= 10) != 0);
- if (neg)
- *s++= '-';
- *s= EOS;
- return(reverse(t));
- } /* itoa */
-
- #ifdef UNIX
- char *
- #endif
- reverse(s) /* reverse string s in place */
- char s[];
- {
- register 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;
- }
- return(s);
- } /* end reverse */