/* ************************************************************************** */ /* */ /* ::: o_ :::::: ::: */ /* ft_atoi.c :+: / :+::+: :+: */ /* +:+ > +:++:+ +:+ */ /* By: whaffman +#+ +:+ +#++#++:++#++ */ /* +#+ +#+#+ +#++#+ +#+ \o/ */ /* Created: 2024/10/10 17:00:13 by whaffman #+#+# #+#+# #+# #+# | */ /* Updated: 2024/10/10 17:00:13 by whaffman ### ### ### ### / \ */ /* */ /* ************************************************************************** */ #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; if (*nptr == '-' || *nptr == '+') { if (*nptr == '-') sign *= -1; nptr++; } while (ft_isdigit(*nptr)) res = 10 * res + sign * (*nptr++ - '0'); return (res); }