/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_atoi.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: kcolin +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/16 16:06:11 by kcolin #+# #+# */ /* Updated: 2024/10/19 17:59:34 by kcolin ### ########.fr */ /* */ /* ************************************************************************** */ #include "libft.h" int ft_isspace(char c) { if (c == ' ' || c == '\f' || c == '\n' || c == '\r' || c == '\t' || c == '\v') return (1); else return (0); } int ft_atoi(const char *nptr) { int result; int i; int sign; result = 0; i = 0; sign = 1; while (ft_isspace(nptr[i])) i++; if (nptr[i] == '+' || nptr[i] == '-') { if (nptr[i] == '-') sign = -1; i++; } while (ft_isdigit(nptr[i])) { result *= 10; result += nptr[i] - '0'; i++; } return (result * sign); } /* #include #include int main(int argc, char **argv) { if (argc > 1) { printf("mine: %d\nlib: %d\n", ft_atoi(argv[1]), atoi(argv[1])); } return (0); } */