summaryrefslogtreecommitdiff
path: root/minix/lib/libc/gen/itoa.c
blob: ac5a84910ee985156d4e457d99459a7e18105657 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include <lib.h>
/* Integer to ASCII for signed decimal integers. */

static int next;
static char qbuf[8];

char *itoa(int n);

char *itoa(int n)
{
  register int r, k;
  int flag = 0;

  next = 0;
  if (n < 0) {
	qbuf[next++] = '-';
	n = -n;
  }
  if (n == 0) {
	qbuf[next++] = '0';
  } else {
	k = 10000;
	while (k > 0) {
		r = n / k;
		if (flag || r > 0) {
			qbuf[next++] = '0' + r;
			flag = 1;
		}
		n -= r * k;
		k = k / 10;
	}
  }
  qbuf[next] = 0;
  return(qbuf);
}