ft_itoa: corrected powers of 10 returning 0

This commit is contained in:
Tanguy MAZE 2018-04-08 16:59:24 +02:00
parent 4fff8a050c
commit fcac81fd24

View File

@ -6,7 +6,7 @@
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */ /* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2018/04/08 11:20:12 by tmaze #+# #+# */ /* Created: 2018/04/08 11:20:12 by tmaze #+# #+# */
/* Updated: 2018/04/08 12:45:55 by tmaze ### ########.fr */ /* Updated: 2018/04/08 16:57:47 by tmaze ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -31,7 +31,7 @@ char *ft_itoa(int n)
nb_nbr = 1; nb_nbr = 1;
nbr = ft_abs(n); nbr = ft_abs(n);
sign = (n < 0); sign = (n < 0);
while (mult < nbr && (nb_nbr++)) while (mult <= nbr && (nb_nbr++))
mult *= 10; mult *= 10;
nb_nbr += sign; nb_nbr += sign;
if ((ret = ft_strnew(nb_nbr)) == NULL) if ((ret = ft_strnew(nb_nbr)) == NULL)