/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_atoi.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: pbonilla +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/11/11 16:00:14 by pbonilla #+# #+# */ /* Updated: 2020/11/18 14:03:00 by pbonilla ### ########.fr */ /* */ /* ************************************************************************** */ #include "libft.h" int ft_atoi(const char *nptr) { int nbr; int sgn; sgn = 1; nbr = 0; while (*nptr && (*nptr == ' ' || *nptr == '\n' || *nptr == '\t' || *nptr == '\v' || *nptr == '\f' || *nptr == '\r')) ++nptr; if (*nptr == '-') sgn *= -1; if (*nptr == '-' || *nptr == '+') ++nptr; while (*nptr && *nptr >= '0' && *nptr <= '9') { nbr = nbr * 10 + (*nptr - 48); ++nptr; } return (nbr * sgn); }