add ft_atof
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user