Rev 647 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 647 | Rev 6412 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | #include "stdio.h" |
1 | #include |
2 | #include "stdlib.h" |
2 | #include |
3 | #include "ctype.h" |
3 | #include |
- | 4 | #include |
|
Line 4... | Line 5... | ||
4 | 5 | ||
5 | /* |
6 | /* |
6 | ** itoa(n,s) - Convert n to characters in s |
7 | ** itoa(n,s) - Convert n to characters in s |
7 | */ |
8 | */ |
8 | void itoa(int n,char* s) |
9 | char* itoa(int n,char* s) |
9 | { |
10 | { |
10 | int sign; |
11 | int sign; |
11 | char *ptr; |
12 | char *ptr; |
12 | ptr = s; |
13 | ptr = s; |
13 | if ((sign = n) < 0) n = -n; |
14 | if ((sign = n) < 0) n = -n; |
14 | do { |
15 | do { |
15 | *ptr++ = n % 10 + '0'; |
16 | *ptr++ = n % 10 + '0'; |
16 | } while ((n = n / 10) > 0); |
17 | } while ((n = n / 10) > 0); |
17 | if (sign < 0) *ptr++ = '-'; |
18 | if (sign < 0) *ptr++ = '-'; |
18 | *ptr = '\0'; |
19 | *ptr = '\0'; |
19 | reverse(s); |
20 | return strrev(s); |