summaryrefslogtreecommitdiffstats
path: root/3/6.c
diff options
context:
space:
mode:
Diffstat (limited to '3/6.c')
-rw-r--r--3/6.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/3/6.c b/3/6.c
index bb3636f..846b7fa 100644
--- a/3/6.c
+++ b/3/6.c
@@ -40,11 +40,12 @@ void reverse(char s[]) {
}
void itoa(int n, char s[], int w) {
- int i;
+ int i, sign;
i = 0;
+ sign = n < 0;
- if (n >= 0) {
+ if (!sign) {
do {
s[i++] = n % 10 + '0';
} while ((n /= 10) > 0);
@@ -54,7 +55,7 @@ void itoa(int n, char s[], int w) {
} while ((n /= 10) <= -1);
}
- if (n < 0)
+ if (sign)
s[i++] = '-';
while (i < MAXLEN - 1 && i < w)