-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_pointer.c
52 lines (48 loc) · 1.54 KB
/
ft_pointer.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
50
51
52
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_pointer.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: taretiuk <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/09 14:51:36 by taretiuk #+# #+# */
/* Updated: 2024/01/26 10:31:16 by taretiuk ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_long_hex(unsigned long long decimal, int *length, char format)
{
char string[100];
char *base_character;
int i;
if (format == 'X')
base_character = "0123456789ABCDEF";
else
base_character = "0123456789abcdef";
i = 0;
if (decimal == 0)
{
ft_char_length('0', length);
return ;
}
while (decimal != 0)
{
string[i] = base_character [decimal % 16];
decimal = decimal / 16;
i++;
}
while (i--)
ft_char_length(string[i], length);
}
void ft_pointer(void *ptr, int *length)
{
if (0 == ptr)
{
write(1, "(nil)", 5);
(*length) += 5;
return ;
}
write(1, "0x", 2);
(*length) += 2;
ft_long_hex((unsigned long long)ptr, length, 'x');
}