add: atoi, atol, atoll
This commit is contained in:
parent
f6da8f1524
commit
e58fdc20b6
5
headers/stdlib.h
Normal file
5
headers/stdlib.h
Normal 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
6
src/stdlib/atoi.c
Normal file
@ -0,0 +1,6 @@
|
||||
#include "../../headers/stdlib.h"
|
||||
|
||||
int atoi(const char *str)
|
||||
{
|
||||
return atoll(str);
|
||||
}
|
6
src/stdlib/atol.c
Normal file
6
src/stdlib/atol.c
Normal file
@ -0,0 +1,6 @@
|
||||
#include "../../headers/stdlib.h"
|
||||
|
||||
long atol(const char *str)
|
||||
{
|
||||
return atoll(str);
|
||||
}
|
13
src/stdlib/atoll.c
Normal file
13
src/stdlib/atoll.c
Normal 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;
|
||||
}
|
Loading…
Reference in New Issue
Block a user