add: atoi, atol, atoll

This commit is contained in:
starnakin 2024-09-06 23:53:45 +02:00
parent f6da8f1524
commit e58fdc20b6
4 changed files with 30 additions and 0 deletions

5
headers/stdlib.h Normal file
View File

@ -0,0 +1,5 @@
#pragma once
int atoi(const char *nptr);
long atol(const char *nptr);
long long atoll(const char *nptr);

6
src/stdlib/atoi.c Normal file
View File

@ -0,0 +1,6 @@
#include "../../headers/stdlib.h"
int atoi(const char *str)
{
return atoll(str);
}

6
src/stdlib/atol.c Normal file
View File

@ -0,0 +1,6 @@
#include "../../headers/stdlib.h"
long atol(const char *str)
{
return atoll(str);
}

13
src/stdlib/atoll.c Normal file
View File

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