/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* generic.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: hulamy +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/01/26 15:30:19 by hulamy #+# #+# */ /* Updated: 2022/01/26 15:31:15 by hulamy ### ########.fr */ /* */ /* ************************************************************************** */ #include "philo.h" int ft_atoi(const char *str) { int i; int result; int is_negative; is_negative = 0; result = 0; i = 0; while (str[i] == ' ' || (str[i] >= 9 && str[i] <= 13)) i++; if (str[i] == '+') i++; else if (str[i] == '-') { is_negative = 1; i++; } while (str[i] >= '0' && str[i] <= '9') { result = (result * 10) + (str[i] - '0'); i++; } if (is_negative) result = result * -1; return (result); }