ajout des fonctions atol free_tab et isnumber

This commit is contained in:
hugogogo
2021-09-27 16:51:48 +02:00
parent c335eb1f6a
commit d622367cfd
11 changed files with 221 additions and 23 deletions
+6
View File
@@ -10,6 +10,12 @@
/* */
/* ************************************************************************** */
/*
** i don't understand the purpose of this function...
** it takes a 2D array, and for each array it checks
** if a function given in parameters is true or false
*/
#include "libft.h"
int ft_any(char **tab, int (*f)(char*))
+6 -12
View File
@@ -14,26 +14,20 @@
int ft_atoi(const char *str)
{
long long nbr;
long nbr;
int i;
int n;
int negatif;
i = 0;
n = 1;
negatif = 1;
nbr = 0;
while ((str[i] == ' ') || (str[i] > 8 && str[i] < 14))
i++;
if (str[i] == '-')
n = -1;
negatif = -1;
if (str[i] == '+' || str[i] == '-')
i++;
while (str[i] >= '0' && str[i] <= '9')
{
if ((nbr >= 922337203685477580
&& ((str[i] > 8 && n < 0) || (str[i] > 7 && n > 0))))
return ((n > 0) ? -1 : 0);
else
nbr = nbr * 10 + (str[i++] - '0');
}
return (nbr * n);
nbr = nbr * 10 + (str[i++] - '0');
return (nbr * negatif);
}
+22
View File
@@ -0,0 +1,22 @@
#include "libft.h"
long ft_atol(const char *str)
{
long long nbr;
int i;
int negatif;
i = 0;
negatif = 1;
nbr = 0;
while ((str[i] == ' ') || (str[i] > 8 && str[i] < 14))
i++;
if (str[i] == '-')
negatif = -1;
if (str[i] == '+' || str[i] == '-')
i++;
while (str[i] >= '0' && str[i] <= '9')
nbr = nbr * 10 + (str[i++] - '0');
return (nbr * negatif);
}
+15
View File
@@ -0,0 +1,15 @@
#include "libft.h"
void ft_free_tab(char **tab)
{
int i;
i = 0;
while (tab[i] != NULL)
{
free(tab[i]);
i++;
}
free(tab);
}
+19
View File
@@ -0,0 +1,19 @@
#include "libft.h"
int ft_isnumber(char *nb)
{
int i;
i = 0;
if (nb[i] == '+' || nb[i] == '-')
i++;
while (nb[i] != '\0')
{
if (ft_isdigit(nb[i]) == 0)
return (0);
i++;
}
return (1);
}