blob: 465e978386d109180229d3b225b582b4332dddee (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
char* int_to_str(int i)
{
// Room for 4 byte int, -ve sign and null terminator
static char buf[12];
char *p = buf + 11; // points to null terminator
if (i >= 0) {
do {
*--p = '0' + (i % 10);
i /= 10;
} while (i != 0);
return p;
}
else {
do {
*--p = '0' - (i % 10);
i /= 10;
} while (i != 0);
*--p = '-';
}
return p;
}
|