/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_atoi.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: gbrochar +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2015/11/27 19:18:43 by gbrochar #+# #+# */ /* Updated: 2019/02/06 16:16:54 by gbrochar ### ########.fr */ /* */ /* ************************************************************************** */ #include "libft.h" int ft_atoi(const char *str) { long result; long sign; result = 0; while (ft_isspace(*str)) str++; sign = (*str == '-') ? -1 : 1; if (*str == '-' || *str == '+') str++; while (*str >= '0' && *str <= '9') { result = (result * 10) + (*str - '0'); str++; } return ((int)(result * sign)); }