-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_printpointer.c
More file actions
59 lines (53 loc) · 1.55 KB
/
ft_printpointer.c
File metadata and controls
59 lines (53 loc) · 1.55 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
52
53
54
55
56
57
58
59
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_printpointer.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: thfranco <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/06 17:13:53 by thfranco #+# #+# */
/* Updated: 2023/11/06 18:34:54 by thfranco ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
static int pointerlen(unsigned long long pointer)
{
int length;
length = 0;
while (pointer != 0)
{
pointer = pointer / 16;
length++;
}
return (length);
}
static int turnhexa(unsigned long long pointer)
{
if (pointer >= 16)
{
turnhexa(pointer / 16);
turnhexa(pointer % 16);
}
else
{
if (pointer <= 9)
ft_printchar(pointer + '0');
else
ft_printchar(pointer - 10 + 'a');
}
return (pointerlen(pointer));
}
int ft_printpointer(unsigned long long pointer)
{
int len;
len = 0;
if (pointer == 0)
{
len += (ft_printstr("(nil)"));
return (len);
}
len = write (1, "0x", 2);
len += pointerlen(pointer);
turnhexa(pointer);
return (len);
}