mobile commit time B)
corrected negative number bug in ft_atois
This commit is contained in:
parent
136cd5efb4
commit
d72a91f9e9
11
ft_atois.c
11
ft_atois.c
@ -6,7 +6,7 @@
|
||||
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user