trios/libk/stdlib.c
2023-04-21 09:39:35 -04:00

20 lines
276 B
C

#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;
}