summaryrefslogtreecommitdiff
path: root/ft_puthexlower.c
blob: 282328a157d82809883bfa9b609232a028a9ed44 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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);
}