ft_printf/ft_putnbr.c
Etienne Rey-bethbeder c70b29dfd1 printf
2022-11-10 15:25:19 +01:00

40 lines
1.2 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putnbr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/05 10:22:16 by erey-bet #+# #+# */
/* Updated: 2022/10/10 22:49:10 by erey-bet ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
int ft_putnbr(int n)
{
int len;
int count;
long nl;
count = 0;
nl = n;
nl *= (n > 0) - (n < 0);
len = ft_get_size(nl);
if (n < 0)
{
ft_putchar('-');
count++;
}
while (len > 1)
{
--len;
ft_putchar(nl / ft_power(10, len) % 10 + 48);
count++;
}
ft_putchar(nl % 10 + 48);
count++;
return (count);
}