libs,klib,stdlib: enhance atoi()
* skip leading space and finish with non-digit character
This commit is contained in:
parent
ae87feded1
commit
b5db2daab5
|
@ -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 ++;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue