/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_atoi.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: whaffman +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/07/05 18:42:02 by whaffman #+# #+# */ /* Updated: 2024/07/09 22:20:16 by whaffman ### ########.fr */ /* */ /* ************************************************************************** */ #include "libft.h" static int ft_isspace(int c) { return (' ' == c || '\f' == c || \ '\n' == c || '\r' == c || \ '\t' == c || '\v' == c); } int ft_atoi(const char *nptr) { int sign; int res; while (ft_isspace(*nptr)) nptr++; res = 0; sign = 1; while (*nptr == '-' || *nptr == '+') { if (*nptr == '-') sign *= -1; nptr++; } while (ft_isdigit(*nptr)) res = 10 * res + sign * (*nptr++ - '0'); return (res); }