/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_atoi.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: aortigos +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/09/22 20:46:43 by aortigos #+# #+# */ /* Updated: 2023/10/18 20:41:03 by aortigos ### ########.fr */ /* */ /* ************************************************************************** */ #include "libft.h" int ft_atoi(const char *str) { int sign; int result; int i; sign = 1; result = 0; i = 0; while ((str[i] == ' ' || str[i] == '\t' || str[i] == '\n') || (str[i] == '\v' || str[i] == '\r' || str[i] == '\f')) i++; if (str[i] == '-') { sign = -1; } if (str[i] == '-' || str[i] == '+') { i++; } while (str[i] >= '0' && str[i] <= '9') { result = result * 10 + (str[i] - '0'); i++; } return (sign * result); }