This commit is contained in:
Tony 2020-06-12 06:26:16 +02:00 committed by GitHub
commit e13378cd67
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,35 +1,42 @@
#include <lib.h> #include <lib.h>
/* Integer to ASCII for signed decimal integers. */ /* Integer to ASCII for signed decimal integers. */
static int next; static char qbuf[12];
static char qbuf[8];
char *itoa(int n); char *itoa(int n);
char *itoa(int n) char *itoa(int n)
{ {
register int r, k; register int r;
int flag = 0; register int k;
int flag = 0;
long long nb = n;
int next = 0;
next = 0; if (nb < 0)
if (n < 0) { {
qbuf[next++] = '-'; qbuf[next++] = '-';
n = -n; nb = -nb;
}
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;
} }
} if (nb == 0)
qbuf[next] = 0; {
return(qbuf); qbuf[next++] = '0';
}
else
{
k = 1000000000;
while (k > 0)
{
r = nb / k;
if (flag || r > 0)
{
qbuf[next++] = '0' + r;
flag = 1;
}
nb -= r * k;
k = k / 10;
}
}
qbuf[next] = 0;
return(qbuf);
} }