libft/ft_putnbr_fd.c
Etienne Rey-bethbeder 191a193cb2 origin
2022-10-11 22:51:06 +02:00

29 lines
1.1 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putnbr_fd.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 "libft.h"
void ft_putnbr_fd(int n, int fd)
{
int len;
long nl;
nl = n;
nl *= (n > 0) - (n < 0);
len = ft_get_size(nl);
if (n < 0)
ft_putchar_fd('-', fd);
while (len > 1)
ft_putchar_fd(nl / ft_power(10, --len) % 10 + 48, fd);
ft_putchar_fd(nl % 10 + 48, fd);
}