42_ft_printf/ft_dprintl_base.c

35 lines
1.2 KiB
C
Raw Permalink Normal View History

2022-10-06 20:30:03 -04:00
/* ************************************************************************** */
/* */
/* ::: :::::::: */
2022-10-23 13:01:50 -04:00
/* ft_dprintl_base.c :+: :+: :+: */
2022-10-06 20:30:03 -04:00
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
2022-10-10 13:33:47 -04:00
/* Created: 2022/10/10 03:26:21 by cchauvet #+# #+# */
2022-10-23 13:01:50 -04:00
/* Updated: 2022/10/21 15:54:31 by cchauvet ### ########.fr */
2022-10-06 20:30:03 -04:00
/* */
/* ************************************************************************** */
2022-10-23 13:01:50 -04:00
#include "ft_printf.h"
2022-10-06 20:30:03 -04:00
2022-10-23 13:01:50 -04:00
int ft_dprintl_base(int fd, long long int n, char *base)
2022-10-06 20:30:03 -04:00
{
2022-10-23 13:01:50 -04:00
int i;
2022-10-10 13:33:47 -04:00
unsigned long nb;
2022-10-06 20:30:03 -04:00
2022-10-10 13:33:47 -04:00
if (base == NULL)
2022-10-23 13:01:50 -04:00
return (-1);
i = 0;
2022-10-06 20:30:03 -04:00
if (n < 0)
{
2022-10-10 13:33:47 -04:00
nb = -n;
2022-10-23 13:01:50 -04:00
i += ft_putchar_fd(fd, '-');
2022-10-06 20:30:03 -04:00
}
else
2022-10-10 13:33:47 -04:00
nb = n;
2022-10-23 13:01:50 -04:00
i += ft_dprintul_base(fd, nb, base);
if (i < 1)
return (-1);
return (i);
2022-10-06 20:30:03 -04:00
}