Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 2022e95

Browse files
Merge pull request begeekmyfriend#9 from vsyf/master
Improve atoi
2 parents a147a57 + 98bc719 commit 2022e95

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

008_atoi/atoi.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ static int myAtoi(char* str)
2626
}
2727
}
2828
n = n * 10 + d;
29-
} else if (*s == '-' && isdigit(*(s + 1))) {
29+
} else if (*s == '-' && isdigit(*(s + 1)) && (n == 0)) {
3030
sign = 1;
31-
} else if (*s == '+' && isdigit(*(s + 1))) {
31+
} else if (*s == '+' && isdigit(*(s + 1)) && (n == 0)) {
3232
sign = 0;
3333
} else {
3434
break;

0 commit comments

Comments
 (0)