-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_puthex_lower.c
46 lines (42 loc) · 1.31 KB
/
ft_puthex_lower.c
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_puthex_lower.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ttavares <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/05 15:11:03 by ttavares #+# #+# */
/* Updated: 2022/12/06 14:54:51 by ttavares ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
static void ft_print_convert(unsigned int num)
{
if (num <= 9)
ft_putchar(num + '0');
else if (num >= 16)
{
ft_print_convert(num / 16);
ft_print_convert(num % 16);
}
else
ft_putchar(num - 10 + 'a');
}
int ft_puthex_lower(unsigned int num)
{
int total;
total = 0;
if (num == 0)
{
ft_putchar('0');
total++;
}
else
ft_print_convert(num);
while (num != 0)
{
num = num / 16;
total++;
}
return (total);
}