2016-04-30 15:50:04 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <string.h>
|
2006-11-21 13:36:25 +01:00
|
|
|
|
|
|
|
/*
|
2016-06-10 13:10:52 +02:00
|
|
|
** itoa(n,s) - Convert n to characters in s
|
2006-11-21 13:36:25 +01:00
|
|
|
*/
|
2016-06-10 13:10:52 +02:00
|
|
|
char* __itoa(int n,char* s)
|
2006-11-21 13:36:25 +01:00
|
|
|
{
|
|
|
|
int sign;
|
|
|
|
char *ptr;
|
|
|
|
ptr = s;
|
2016-06-10 13:10:52 +02:00
|
|
|
|
|
|
|
if(n == (int)0x80000000)
|
|
|
|
return strcpy(s, "-2147483648"); // overflowed -n
|
|
|
|
|
2006-11-21 13:36:25 +01:00
|
|
|
if ((sign = n) < 0) n = -n;
|
|
|
|
do {
|
|
|
|
*ptr++ = n % 10 + '0';
|
|
|
|
} while ((n = n / 10) > 0);
|
|
|
|
if (sign < 0) *ptr++ = '-';
|
|
|
|
*ptr = '\0';
|
2016-04-30 15:50:04 +02:00
|
|
|
return strrev(s);
|
2006-11-21 13:36:25 +01:00
|
|
|
}
|
|
|
|
|