/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_atoi.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: exam +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/26 11:11:42 by exam #+# #+# */ /* Updated: 2019/07/26 11:32:51 by exam ### ########.fr */ /* */ /* ************************************************************************** */ int ft_atoi(const char *str) { int nb; int is_negative; while (*str == ' ' || *str == '\t' || *str == '\n' || *str == '\r' || *str == '\v' || *str == '\f'|| *str == '\r') str++; is_negative = 0; if (*str == '+' || *str == '-') { if (*str == '-') is_negative = 1; str++; } nb = 0; while (*str >= '0' && *str <= '9') { nb *= 10; nb += *str - '0'; str++; } if (is_negative) nb = -nb; return (nb); }