0
0
This commit is contained in:
Guy Baconniere
2021-08-21 19:03:19 +02:00
parent 681c2242b9
commit ea62cdfc05
16 changed files with 522 additions and 0 deletions

View File

@@ -0,0 +1,38 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_atoi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gbaconni <gbaconni@42lausanne.ch> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/08/21 14:02:34 by gbaconni #+# #+# */
/* Updated: 2021/08/21 16:15:10 by gbaconni ### ########.fr */
/* */
/* ************************************************************************** */
int ft_atoi(char *str)
{
int nb;
int s;
int i;
nb = 0;
s = 1;
i = 0;
while (str[i] != '\0' && \
(str[i] == ' ' || (str[i] >= '\t' && str[i] <= '\r')))
i++;
while (str[i] != '\0')
{
if (str[i] == '+')
s += 0;
else if (str[i] == '-')
s *= -1;
else if (str[i] >= '0' && str[i] <= '9')
nb = nb * 10 + str[i] - '0';
else
break ;
i++;
}
return (nb * s);
}