-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_printf_ptr.c
56 lines (49 loc) · 1.48 KB
/
ft_printf_ptr.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
53
54
55
56
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_printf_ptr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jikarunw <jikarunw@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/09/16 22:35:42 by jikarunw #+# #+# */
/* Updated: 2023/09/18 16:45:54 by jikarunw ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
static int ft_size_hex_adr(unsigned long long n)
{
int size;
size = 0;
if (n == 0)
return (1);
while (n)
{
size++;
n /= 16;
}
return (size);
}
static int ft_hex_adr(unsigned long long n)
{
char *base_16;
int size;
size = ft_size_hex_adr(n);
base_16 = "0123456789abcdef";
while (size > 0)
{
size--;
ft_printf_char(base_16[(n >> (size * 4)) & 0xf]);
}
return (ft_size_hex_adr(n));
}
int ft_printf_ptr(void *ptr)
{
int n;
if (ft_printf_string("0x") == -1)
return (-1);
n = ft_hex_adr((unsigned long long) ptr);
if (n != 0)
return (n + 2);
else
return (3);
}