-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_putptr.c
49 lines (45 loc) · 1.37 KB
/
ft_putptr.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
47
48
49
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putptr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ttavares <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/05 15:53:35 by ttavares #+# #+# */
/* Updated: 2022/12/06 15:04:40 by ttavares ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
static void ft_print_convert(unsigned long long 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_putptr(unsigned long long num)
{
int total;
total = 0;
if (num == 0)
{
write(1, "(nil)", 5);
return (total + 5);
}
else
{
write(1, "0x", 2);
ft_print_convert(num);
}
while (num != 0)
{
total++;
num = num / 16;
}
return (total + 2);
}