42_cub3d/Libft/ft_atoi.c
2024-10-09 03:35:09 +02:00

34 lines
1.2 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_atoi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: grobledo <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/04 14:30:22 by grobledo #+# #+# */
/* Updated: 2023/02/04 14:30:24 by grobledo ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_atoi(const char *str)
{
int i;
int is_neg;
int number;
i = 0;
is_neg = 1;
number = 0;
while ((str[i] >= 9 && str[i] <= 13) || str[i] == 32)
i++;
if (str[i] == '-' || str[i] == '+')
{
if (str[i] == '-')
is_neg *= -1;
i++;
}
while (str [i] >= '0' && str[i] <= '9')
number = (number * 10) + str[i++] - 48;
return (number * is_neg);
}