/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_putnbr.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: bchanot +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/03/03 02:08:12 by bchanot #+# #+# */ /* Updated: 2016/04/25 00:37:31 by bchanot ### ########.fr */ /* */ /* ************************************************************************** */ #include "libftprintf.h" #include int pf_puthex(unsigned int n, int fd) { char *hex; hex = NULL; if (n >= 16) return (pf_puthex(n / 16, fd) + pf_puthex(n % 16, fd)); else { hex = ft_strdup("0123456789abcdef"); ft_putchar_fd(hex[n], fd); if (hex) free(hex); return (1); } } int pf_putoctal(unsigned int n, int fd) { if (n >= 8) return (pf_putoctal(n / 8, fd) + pf_puthex(n % 8, fd)); else { ft_putchar_fd(n + 48, fd); return (1); } } int pf_puthexm(unsigned int n, int fd) { char *hex; hex = NULL; if (n >= 16) return (pf_puthexm(n / 16, fd) + pf_puthexm(n % 16, fd)); else { hex = ft_strdup("0123456789ABCDEF"); ft_putchar_fd(hex[n], fd); if (hex) free(hex); return (1); } } int pf_putunbr(unsigned int n, int fd) { if (n >= 10) return (pf_putunbr(n / 10, fd) + pf_putunbr(n % 10, fd)); ft_putchar_fd(48 + n, fd); return (1); }