-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_ptr.c
71 lines (63 loc) · 1.82 KB
/
ft_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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_ptr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: asibille <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/01/18 10:04:12 by asibille #+# #+# */
/* Updated: 2022/01/18 10:04:18 by asibille ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
static size_t ft_find_div(size_t ptr)
{
size_t div;
div = 1152921504606846976;
while (!(ptr / div))
div /= 16;
return (div);
}
static void ft_fill_hexaset(char *hexaset)
{
int i;
i = 0;
while (i < 10)
{
hexaset[i] = '0' + i;
++i;
}
while (i < 16)
{
hexaset[i] = 'a' + i - 10;
++i;
}
}
static void ft_putptr_count(size_t ptr, int fd, int *size)
{
char hexaset[16];
size_t div;
ft_fill_hexaset(hexaset);
if (!ptr)
div = 1;
else
div = ft_find_div(ptr);
ft_putstr_count("0x", 1, size);
while (div > 1)
{
ft_putchar_count(hexaset[ptr / div], fd, size);
ptr %= div;
div /= 16;
}
ft_putchar_count(hexaset[ptr], fd, size);
}
void ft_ptr(void *ptr, t_conv_flags *fl, int *size)
{
fl->hashtag = 1;
if (!(fl->minus))
ft_flag_width_x((size_t) ptr, fl, size);
if ((fl->point) || ptr || !(fl->ispoint))
ft_putptr_count((size_t) ptr, 1, size);
if (fl->minus)
ft_flag_width_x((size_t) ptr, fl, size);
}