-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_pointer.c
More file actions
72 lines (67 loc) · 2.12 KB
/
ft_pointer.c
File metadata and controls
72 lines (67 loc) · 2.12 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
60
61
62
63
64
65
66
67
68
69
70
71
72
/* ************************************************************************** */
/* */
/* :::::::: */
/* ft_pointer.c :+: :+: */
/* +:+ */
/* By: oswin <oswin@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2021/01/27 21:41:30 by oswin #+# #+# */
/* Updated: 2021/02/14 13:26:53 by obult ######## odam.nl */
/* */
/* ************************************************************************** */
#include "printf.h"
int ft_prep_ptr(va_list *ap, char **format)
{
t_prep n;
void *ptr;
n.right = 0;
n.width = ft_width(*format + 1, ap, &(n.right));
n.precision = ft_precision(*format, ap);
ptr = va_arg(*ap, void*);
n.min = 0;
n.zero = 32;
n.len = ft_writelen_b((size_t)ptr, 16);
n.superiorlen = n.len;
if (n.precision > n.len)
n.superiorlen = n.precision;
n.superiorlen = n.superiorlen + 2;
if ((*format)[1] == '0')
n.zero = 48;
if ((*format)[1] == '-' || (*format)[2] == '-')
n.right = 1;
if (!(ptr || n.precision))
n.superiorlen = 2;
return (ft_pointer(n, ptr));
}
int ft_pointer(t_prep info, void *ptr)
{
if (info.precision > 0)
{
if (!info.right)
ft_putwidth(info.width - info.superiorlen, ' ');
ft_putstring("0x");
ft_putwidth(info.precision - info.len, '0');
}
else
{
if (!info.right)
{
if (info.zero == 48)
ft_putstring("0x");
ft_putwidth(info.width - info.superiorlen, info.zero);
}
if (info.zero != 48)
ft_putstring("0x");
}
if (ptr || info.precision)
ft_putnbr_b((size_t)ptr, "0123456789abcdef", 16);
if (info.right)
ft_putwidth(info.width - info.superiorlen, ' ');
return (ft_retour(info.superiorlen, info.width));
}
int ft_retour(int a, int b)
{
if (a > b)
return (a);
return (b);
}