add ft_atof

This commit is contained in:
hugogogo
2026-04-29 00:52:48 +02:00
parent 2be81d5630
commit f86c2cf5cb
5 changed files with 67 additions and 9 deletions

View File

@@ -12,22 +12,29 @@
#include "libft.h"
int ft_atoi(const char *str)
int ft_atoi(const char *str)
{
long nbr;
int i;
int negatif;
long nbr;
int i;
int negatif;
i = 0;
negatif = 1;
nbr = 0;
// Skip leading whitespace
while ((str[i] == ' ') || (str[i] > 8 && str[i] < 14))
i++;
// Handle optional sign
if (str[i] == '-')
negatif = -1;
if (str[i] == '+' || str[i] == '-')
i++;
// parse integer
while (str[i] >= '0' && str[i] <= '9')
nbr = nbr * 10 + (str[i++] - '0');
return (nbr * negatif);
}