first commit of v2 ft_printf
This commit is contained in:
35
42-libft/ft_putnbr_fd.c
Normal file
35
42-libft/ft_putnbr_fd.c
Normal file
@@ -0,0 +1,35 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_putnbr_fd.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: dgaillet <dgaillet@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/11/08 17:50:35 by dgaillet #+# #+# */
|
||||
/* Updated: 2025/11/11 12:26:48 by dgaillet ### ########lyon.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
static void write_nbr(unsigned int n, int fd)
|
||||
{
|
||||
if (n)
|
||||
{
|
||||
write_nbr(n / 10, fd);
|
||||
ft_putchar_fd(n % 10 + '0', fd);
|
||||
}
|
||||
}
|
||||
|
||||
void ft_putnbr_fd(int n, int fd)
|
||||
{
|
||||
if (!n)
|
||||
ft_putchar_fd('0', fd);
|
||||
else if (n < 0)
|
||||
{
|
||||
ft_putchar_fd('-', fd);
|
||||
write_nbr(n * -1, fd);
|
||||
}
|
||||
else
|
||||
write_nbr(n, fd);
|
||||
}
|
||||
Reference in New Issue
Block a user