diff options
Diffstat (limited to 'ft_puthexlower.c')
| -rw-r--r-- | ft_puthexlower.c | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/ft_puthexlower.c b/ft_puthexlower.c new file mode 100644 index 0000000..282328a --- /dev/null +++ b/ft_puthexlower.c @@ -0,0 +1,30 @@ + +// parameter is unsigned long so function does not +// overflow when LONG_MAX is the address +// we use recursion to print backwards + +#include "ft_printf.h" + +int ft_puthexlower(unsigned long n) +{ + const char hex[16] = "0123456789abcdef"; + int save; + int remainder; + int counter; + + remainder = 0; + save = 0; + counter = 0; + if (n > 15) + { + save = n; + n /= 16; + remainder = save - (n * 16); + counter += ft_puthexlower(n); + counter += write(1, &hex[remainder], 1); + } + else + counter += write(1, &hex[n], 1); + return (counter); +} + |
