on/usr/src/cmd/fmli/sys/itoa.c
#pragma ident "@(#)itoa.c 1.6 05/06/08 SMI"
31
32 char *
33 itoa(n, base)
34 long n; /* abs k16 */
35 int base;
36 {
37 register char *p;
38 register int minus;
39 static char buf[36];
40
41 p = &buf[36];
42 *--p = '\0';
43 if (n < 0) {
44 minus = 1;
45 n = -n;
46 }
47 else
48 minus = 0;
49 if (n == 0)
50 *--p = '0';
51 else
52 while (n > 0) {
53 *--p = "0123456789abcdef"[n % base];
54 n /= base;
55 }
56 if (minus)
57 *--p = '-';
58 return p;
59 }
60
阅读(488) | 评论(0) | 转发(0) |