42_C_PISCINE/C/c04v1/ex03/ft_atoi.c
Camille Chauvet 29ed24d567 init
2023-05-17 16:45:25 +00:00

37 lines
1.2 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_atoi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/19 10:08:23 by cchauvet #+# #+# */
/* Updated: 2022/07/25 10:00:39 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
int ft_atoi(char *str)
{
int i;
int sign;
int nbr;
i = 0;
sign = 1;
nbr = 0;
while (str[i] == ' ')
i++;
while (str[i] == '+' || str[i] == '-')
{
if (str[i] == '-')
sign = sign * -1;
i++;
}
while (str[i] >= '0' && str[i] <= '9')
{
nbr = (nbr * 10 + (str[i] - '0'));
i++;
}
return (nbr * sign);
}