-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_voidtohex.c
41 lines (38 loc) · 1.28 KB
/
ft_voidtohex.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_voidtohex.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gyong-si <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/09/28 09:58:41 by gyong-si #+# #+# */
/* Updated: 2023/09/30 12:58:02 by gyong-si ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
int ft_voidtohex(void *p)
{
unsigned long long addr;
int i;
int len;
char hex[16];
len = 0;
i = 0;
addr = (unsigned long long)p;
if (!addr)
return(ft_int_putstr_fd("(nil)", 1));
while (addr > 0)
{
hex[i] = "0123456789abcdef"[addr % 16];
addr /= 16;
len++;
i++;
}
ft_putstr_fd("0x", 1);
while (i > 0)
{
i--;
ft_putchar_fd(hex[i], 1);
}
return (len + 2);
}