/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_atoi.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/08/08 15:39:51 by jhalford #+# #+# */ /* Updated: 2016/08/15 10:28:47 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ int ft_is_whitespace(char c) { if (c == ' ' || c == '\t' || c == '\n') return (1); else if (c == '\v' || c == '\f' || c == '\r') return (1); else return (0); } int ft_atoi(char *str) { int i; int res; int sign; i = 0; res = 0; sign = 1; while (ft_is_whitespace(str[i])) i++; if (str[i] == '-' || str[i] == '+') { if (str[i + 1] >= '0' && str[i + 1] <= '9') { sign = (str[i] == '+') ? 1 : -1; i++; } else return (0); } while (str[i] >= '0' && str[i] <= '9') res = res * 10 + sign * (str[i++] - '0'); return (res); }