trios/libk/stdlib.c

20 lines
276 B
C
Raw Normal View History

2023-04-19 03:44:10 +00:00
#include <stdbool.h>
#include "include/stdlib.h"
int atoi(const char* s) {
bool neg = false;
if(*s == '+') {
s++;
} else if(*s == '-') {
neg = true;
s++;
}
int n = 0;
while(*s >= '0' && *s <= '9') {
n *= 10;
n += (*s - '0');
s++;
}
return neg ? -n : n;
}