libs,klib,stdlib: enhance atoi()

* skip leading space and finish with non-digit character
This commit is contained in:
Zihao Yu 2020-02-06 23:03:13 +08:00
parent ae87feded1
commit b5db2daab5
1 changed files with 2 additions and 1 deletions

View File

@ -19,7 +19,8 @@ int abs(int x) {
int atoi(const char* nptr) {
int x = 0;
while (*nptr != '\0') {
while (*nptr == ' ') { nptr ++; }
while (*nptr >= '0' && *nptr <= '9') {
x = x * 10 + *nptr - '0';
nptr ++;
}