From d72a91f9e9d8f8d5a09543f714a77521e38ad6a9 Mon Sep 17 00:00:00 2001 From: tanguy maze Date: Wed, 27 Feb 2019 18:29:17 +0100 Subject: [PATCH] mobile commit time B) corrected negative number bug in ft_atois --- ft_atois.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/ft_atois.c b/ft_atois.c index 7cae05b..c10071a 100644 --- a/ft_atois.c +++ b/ft_atois.c @@ -6,7 +6,7 @@ /* By: tmaze +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/02/27 11:58:44 by tmaze #+# #+# */ -/* Updated: 2019/02/27 13:14:18 by tmaze ### ########.fr */ +/* Updated: 2019/02/27 17:15:04 by tmaze ### ########.fr */ /* */ /* ************************************************************************** */ @@ -30,17 +30,12 @@ int ft_atois(const char *str, int *nb) *nb = 0; mult = 1; while (num >= 0 && ft_isdigit(str[num]) && - (max - *nb >= 2000000000)) + (ft_abs(max - *nb) >= 2000000000)) { - ft_putnbr(*nb); - ft_putchar('\n'); - ft_putnbr(max - *nb); - ft_putchar('\n'); *nb += (str[num--] - '0') * mult; mult *= 10; } if (num >= 0 && str[num] == '-') *nb *= -1; - return (!ft_isdigit(str[num]) || (max - *nb >= 2000000000 - * (max < 0) ? -1 : 1)); + return (!ft_isdigit(str[num]) || ft_abs(max - *nb) >= 2000000000); }