ft_printf/ft_putvd.c
Etienne Rey-bethbeder c70b29dfd1 printf
2022-11-10 15:25:19 +01:00

48 lines
1.3 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putvd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/14 23:01:21 by erey-bet #+# #+# */
/* Updated: 2022/10/15 22:15:15 by erey-bet ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
static int ft_putnbrhexull(unsigned long v)
{
int tmp;
int count;
count = 0;
tmp = 0;
while (v > 0)
{
tmp = v % 16;
if (tmp < 10)
ft_putchar(tmp + 48);
else
ft_putchar(tmp + 87);
v = v / 16;
count++;
}
return (count);
}
int ft_putvd(void *v)
{
int count;
unsigned long u;
if (v == NULL)
return (-2);
u = (unsigned long)v;
count = 2;
ft_putstr("0x");
count += ft_putnbrhexull(u);
return (count);
}