libft/ft_putnbr_fd.c
Etienne Rey-bethbeder b891447a0d 3.0
2022-10-14 22:43:08 +02:00

32 lines
1.2 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)
{
--len;
ft_putchar_fd(nl / ft_power(10, len) % 10 + 48, fd);
}
ft_putchar_fd(nl % 10 + 48, fd);
}