/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_atoi.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: bchanot +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2015/11/23 17:07:30 by bchanot #+# #+# */ /* Updated: 2018/10/13 19:54:48 by bchanot ### ########.fr */ /* */ /* ************************************************************************** */ #include "libft.h" int ft_atoi(const char *src) { int nb; t_bool neg; neg = false; nb = 0; if (!src) return (0); while (*src == ' ' || (*src >= 7 && *src <= 15)) src++; if (*src == '-') neg = true; if (*src == '+' || *src == '-') src++; while (*src >= '0' && *src <= '9') { nb *= 10; nb += (*src - 48); src++; } return (neg ? -nb : nb); }