/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_hexa.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: grobledo +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/04/04 09:38:27 by grobledo #+# #+# */ /* Updated: 2023/04/04 09:38:28 by grobledo ### ########.fr */ /* */ /* ************************************************************************** */ #include "libft.h" int ft_hexa(unsigned int args, char format, int count) { char *base; char *shiftbase; base = "0123456789abcdef"; shiftbase = "0123456789ABCDEF"; if (format == 'x') { if (args >= 16) count = ft_hexa(args / 16, format, count); count = ft_putcharf(base[args % 16], count); return (count); } if (format == 'X') { if (args >= 16) count = ft_hexa(args / 16, format, count); count = ft_putcharf(shiftbase[args % 16], count); return (count); } return (0); } int ft_starthexa(unsigned int args, char format, int count) { if (!args && (format == 'x' || format == 'X')) return (ft_putcharf('0', count)); count = ft_hexa(args, format, count); return (count); } int ft_startpointer(unsigned long long int args, char format, int count) { if (!args) return (ft_putstrf("(nil)", count)); count = ft_putstrf("0x", count); count = ft_pointer(args, format, count); return (count); } int ft_pointer(unsigned long long int args, char format, int count) { char *base; base = "0123456789abcdef"; if (args >= 16) count = ft_pointer(args / 16, format, count); count = ft_putcharf(base[args % 16], count); return (count); }