-
Notifications
You must be signed in to change notification settings - Fork 1
/
ft_print_ptr.c
62 lines (56 loc) · 1.64 KB
/
ft_print_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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_print_ptr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mcombeau <mcombeau@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/12/11 15:49:21 by mcombeau #+# #+# */
/* Updated: 2021/12/13 12:13:11 by mcombeau ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
void ft_print_adr(unsigned long int n)
{
if (n >= 16)
{
ft_print_adr(n / 16);
ft_print_adr(n % 16);
}
else
{
if (n < 10)
ft_print_c(n + '0');
else if (n >= 10)
ft_print_c((n - 10) + 'a');
}
}
int ft_print_p(unsigned long int n)
{
int count;
count = 0;
if (n == 0)
{
count += ft_print_s(PTRNULL);
return (count);
}
count += ft_print_s("0x");
ft_print_adr(n);
count += ft_ptr_len(n);
return (count);
}
int ft_print_ptr(unsigned long int n, t_flags flags)
{
int count;
count = 0;
if (n == 0)
flags.width -= ft_strlen(PTRNULL) - 1;
else
flags.width -= 2;
if (flags.left == 1)
count += ft_print_p(n);
count += ft_pad_width(flags.width, ft_ptr_len(n), 0);
if (flags.left == 0)
count += ft_print_p(n);
return (count);
}