This commit is contained in:
Camille Chauvet
2023-05-17 16:45:25 +00:00
commit 29ed24d567
619 changed files with 16119 additions and 0 deletions

36
C/c04v1/ex03/ft_atoi.c Normal file
View File

@ -0,0 +1,36 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* 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);
}