-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprint_p.c
62 lines (56 loc) · 1.58 KB
/
print_p.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* print_p.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jilai <jilai@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/04 20:02:03 by jilai #+# #+# */
/* Updated: 2024/04/04 20:02:05 by jilai ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
int print_p(unsigned long p, t_fopt *opt)
{
int len;
len = 0;
if (!p)
opt->width -= ft_strlen(NULLPTR) - 1;
else
opt->width -= 2;
if (opt->left == 1)
len += print_ptr(p);
len += put_spa_zer(opt->width, len_in_hexl(p), 0);
if (opt->left == 0)
len += print_ptr(p);
return (len);
}
int print_ptr(unsigned long p)
{
int len;
len = 0;
if (!p)
{
len += print_str(NULLPTR);
return (len);
}
len += print_str("0x");
print_in_hex(p);
len += len_in_hexl(p);
return (len);
}
void print_in_hex(unsigned long n)
{
if (n >= 16)
{
print_in_hex(n / 16);
print_in_hex(n % 16);
}
else
{
if (n <= 9)
print_char(n + '0');
else if (n > 9)
print_char((n - 10) + 'a');
}
}