/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_atoi.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: fgras-ca +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/02/11 16:16:54 by fgras-ca #+# #+# */ /* Updated: 2023/02/21 09:57:55 by fgras-ca ### ########.fr */ /* */ /* ************************************************************************** */ #include "libft.h" int ft_atoi(const char *nptr) { int i; int sign; int res; i = 0; sign = 1; res = 0; while (nptr[i] == 32 || (nptr[i] >= 9 && nptr[i] <= 13)) i++; if (nptr[i] == '-' || nptr[i] == '+') { if (nptr[i] == '-') sign = - (1); i++; } while (nptr[i] >= 48 && nptr[i] <= 57) { res = res * 10 + nptr[i] - 48; i++; } return (res * sign); }