feat: add atoi function

This commit is contained in:
2025-10-11 22:39:55 +02:00
parent 327d115d41
commit e3b830202f
3 changed files with 42 additions and 1 deletions

23
ft_atoi.c Normal file
View File

@@ -0,0 +1,23 @@
#include "libft.h"
int ft_atoi(const char *str)
{
int value;
size_t len;
size_t i;
int n;
value = 0;
len = ft_strlen(str);
i = 0;
while (i < len)
{
if (!ft_isdigit(str[i]))
return (value);
n = (int)(str[i] - '0');
value *= 10;
value += n;
i++;
}
return (value);
}