diff --git a/headers/stdlib.h b/headers/stdlib.h new file mode 100644 index 0000000..3510f6d --- /dev/null +++ b/headers/stdlib.h @@ -0,0 +1,5 @@ +#pragma once + +int atoi(const char *nptr); +long atol(const char *nptr); +long long atoll(const char *nptr); \ No newline at end of file diff --git a/src/stdlib/atoi.c b/src/stdlib/atoi.c new file mode 100644 index 0000000..7d8595f --- /dev/null +++ b/src/stdlib/atoi.c @@ -0,0 +1,6 @@ +#include "../../headers/stdlib.h" + +int atoi(const char *str) +{ + return atoll(str); +} \ No newline at end of file diff --git a/src/stdlib/atol.c b/src/stdlib/atol.c new file mode 100644 index 0000000..2ce9be3 --- /dev/null +++ b/src/stdlib/atol.c @@ -0,0 +1,6 @@ +#include "../../headers/stdlib.h" + +long atol(const char *str) +{ + return atoll(str); +} \ No newline at end of file diff --git a/src/stdlib/atoll.c b/src/stdlib/atoll.c new file mode 100644 index 0000000..4a72c5e --- /dev/null +++ b/src/stdlib/atoll.c @@ -0,0 +1,13 @@ +#include "../../headers/ctype.h" + +long long atoll(const char *str) +{ + const char *start = str; + long long ret; + + while (*start != '\0') { + if (isdigit(*str)) + ret = ret * 10 + *str - '0'; + } + return ret; +} \ No newline at end of file