printf/libftprintf/ft_ptrhex_pf.c
2023-12-12 17:40:08 +01:00

32 lines
1.2 KiB
C
Executable File

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_ptrhex_pf.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/18 13:31:16 by fgras-ca #+# #+# */
/* Updated: 2023/03/21 14:45:30 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
#include "../ft_printf.h"
int ft_ptrhex_pf(unsigned long c, int pref)
{
int count;
count = 0;
if (!c)
return (write(1, "(nil)", 5));
if (pref == 1)
{
count += write(1, "0x", 2);
pref = 0;
}
if (c >= 16)
count += ft_ptrhex_pf(c / 16, pref);
write(1, &"0123456789abcdef"[c % 16], 1);
return (count + 1);
}