From 9bf197acbd603df877c54d1b33b18dcb224e39ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zo=C3=ABy=20Noort?= Date: Sun, 11 May 2025 19:23:01 +0200 Subject: [PATCH] feat: added ft_puthex --- srcs/ft_puthex.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 srcs/ft_puthex.c diff --git a/srcs/ft_puthex.c b/srcs/ft_puthex.c new file mode 100644 index 0000000..6958c8c --- /dev/null +++ b/srcs/ft_puthex.c @@ -0,0 +1,12 @@ +#include "libft.h" // for ft_putchar + +int ft_puthex(unsigned int n, int uppercase) +{ + int count = 0; + char *digits = uppercase ? "0123456789ABCDEF" : "0123456789abcdef"; + + if (n >= 16) + count += ft_puthex(n / 16, uppercase); + count += ft_putchar(digits[n % 16]); + return count; +} \ No newline at end of file