-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_print_pointer.c
More file actions
51 lines (46 loc) · 1.39 KB
/
ft_print_pointer.c
File metadata and controls
51 lines (46 loc) · 1.39 KB
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
50
51
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_print_pointer.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bsousa-d <bsousa-d@student.42porto.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/08/03 14:40:29 by bsousa-d #+# #+# */
/* Updated: 2023/08/03 14:42:34 by bsousa-d ### ########.fr */
/* */
/* ************************************************************************** */
#include "../includes/ft_printf.h"
static int print_lenght(unsigned long c)
{
int len;
len = 0;
while (c)
{
len++;
c /= 16;
}
return (len);
}
void print_hexadecimal(unsigned long c)
{
if (c >= 16)
{
print_hexadecimal(c / 16);
print_hexadecimal(c % 16);
}
else
{
if (c <= 9)
ft_print_char(c + '0');
else
ft_print_char(c - 10 + 'a');
}
}
int ft_print_pointer(unsigned long c)
{
if (!c)
return (write(1, "(nil)", 5));
write(1, "0x", 2);
print_hexadecimal(c);
return (print_lenght(c) + 2);
}