Compare commits

..

2 Commits

Author SHA1 Message Date
8d9ebecadd add: isdigit 2024-09-06 23:53:58 +02:00
e58fdc20b6 add: atoi, atol, atoll 2024-09-06 23:53:45 +02:00
6 changed files with 69 additions and 0 deletions

35
headers/ctype.h Normal file
View File

@ -0,0 +1,35 @@
#pragma once
/*
int isalnum(int c);
int isalpha(int c);
int iscntrl(int c);
*/
int isdigit(int c);
/*
int isgraph(int c);
int islower(int c);
int isprint(int c);
int ispunct(int c);
int isspace(int c);
int isupper(int c);
int isxdigit(int c);
int isascii(int c);
int isblank(int c);
int isalnum_l(int c, locale_t locale);
int isalpha_l(int c, locale_t locale);
int isblank_l(int c, locale_t locale);
int iscntrl_l(int c, locale_t locale);
int isdigit_l(int c, locale_t locale);
int isgraph_l(int c, locale_t locale);
int islower_l(int c, locale_t locale);
int isprint_l(int c, locale_t locale);
int ispunct_l(int c, locale_t locale);
int isspace_l(int c, locale_t locale);
int isupper_l(int c, locale_t locale);
int isxdigit_l(int c, locale_t locale);
int isascii_l(int c, locale_t locale);
*/

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);

4
src/ctype/isdigit.c Normal file
View File

@ -0,0 +1,4 @@
int isdigit(int c)
{
return '9' >= c && c >= '0';
}

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