Ejemplo n.º 1
0
void	ft_putnbr_base_s(int fd, long nbr, int base, int caps)
{
	char	*s_base;

	s_base = NULL;
	if (base == 2)
		s_base = "01";
	else if (base == 10)
		s_base = "0123456789";
	else if (base == 8)
		s_base = "01234567";
	else if (base == 16 && (!caps))
		s_base = "0123456789abcdef";
	else if (base == 16 && caps)
		s_base = "0123456789ABCDEF";
	if (nbr < 0)
	{
		ft_putchar_fd('-', fd);
		ft_putnbr_base_u(fd, -nbr, base, caps);
	}
	if (nbr >= (long) ft_strlen(s_base))
		ft_putnbr_base_u(fd, nbr / ft_strlen(s_base), base, caps);
	if (nbr >= 0)
		ft_putchar_fd(s_base[nbr % ft_strlen(s_base)], fd);
}
Ejemplo n.º 2
0
int		ft_putoctal_pf(va_list ap, int nbb)
{
	int					i;
	int					nb2;
	unsigned int		nb;

	i = 0;
	nb = va_arg(ap, unsigned int);
	nb2 = ft_return_nb_nb(nb, "01234567");
	while (i++ < nbb - nb2)
		ft_putchar(' ');
	return (ft_putnbr_base_u(nb, "01234567") + i);
}
Ejemplo n.º 3
0
void	ft_putnbr_base_u(int fd, long unsigned int nbr, int base, int caps)
{
	char	*s_base;

	s_base = NULL;
	if (base == 2)
		s_base = "01";
	else if (base == 10)
		s_base = "0123456789";
	else if (base == 8)
		s_base = "01234567";
	else if (base == 16 && (!caps))
		s_base = "0123456789abcdef";
	else if (base == 16 && caps)
		s_base = "0123456789ABCDEF";
	if (nbr >= ft_strlen(s_base))
		ft_putnbr_base_u(fd, nbr / ft_strlen(s_base), base, caps);
	ft_putchar_fd(s_base[nbr % ft_strlen(s_base)], fd);
}