Wed, 06 Dec 2023 00:42:55 +0100
2 files changed,
25 insertions(+),
0 deletions(-)
A
libcedos/stdlib.c
@@ -0,0 +1,23 @@
+#include "stdlib.h" + +int atoi (const char * str) { + int res = 0; + int sign = 1; + int i = 0; + + if (str[0] == '+') { + sign = 1; + i = 1; + } else if (str[0] == '-') { + sign == -1; + i = 1; + } else if (str[0] < '0' || str[0] > '9') { + return 0; + } + + while (str[i] >= '0' && str[i] <= '9') { + res = 10 * res + (str[i++] - '0'); + } + + return res; +}
M
libcedos/stdlib.h
→
libcedos/stdlib.h
@@ -41,4 +41,6 @@ */
void free(void* ptr); +int atoi (const char * str); + #endif