blob: 3e3e0370555019dc10449cddfbfd2accda5c3576 (
plain) (
blame)
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
36
37
38
|
#include <stdio.h>
#define MAXLEN 30
char* itoa(char str[], int num);
int
main(void)
{
char str[MAXLEN];
int num;
num = -69420;
printf("%d\n", num);
printf("%s\n", itoa(str, num));
return 0;
}
char*
itoa(char str[], int num)
{
static int i = 0;
if (num < 0) {
num = -num;
str[i++] = '-';
}
if (num/10)
itoa(str, num/10);
str[i++] = '0' + (num % 10);
str[i] = '\0';
return str;
}
|