-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_print_2pointers.c
49 lines (44 loc) · 1.96 KB
/
ft_print_2pointers.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_print_2pointers.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: guilmira <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/06/29 12:31:24 by guilmira #+# #+# */
/* Updated: 2021/09/23 08:16:42 by guilmira ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
/** PURPOSE : prints necessary left spaces for hexadecimal converter */
static void print_left_allignment(int lenght_of_hexadecimal, t_flag *flag)
{
while (flag->alignment_total_spaces-- > lenght_of_hexadecimal + 2)
pf_putchar_fd(' ', 1, flag);
}
/** PURPOSE : prints necessary right spaces for hexadecimal converter */
static void print_right_allignment(int lenght_of_hexadecimal, t_flag *flag)
{
while (flag->alignment_total_spaces-- > lenght_of_hexadecimal + 2)
pf_putchar_fd(' ', 1, flag);
}
/** PURPOSE : prints %p, %x and %X converter
* Takes into account: Alignment */
void print_pointer(unsigned long long n, t_flag *flag)
{
int lenght_of_hexadecimal;
unsigned long long counter;
counter = n / 16;
lenght_of_hexadecimal = 1;
while (counter > 0)
{
lenght_of_hexadecimal++;
counter /= 16;
}
if (flag->alignment && flag->alignment_sign == '+')
print_left_allignment(lenght_of_hexadecimal, flag);
pf_putstr_fd("0x", 1, flag);
pf_pointer_fd(n, HEXADECIMAL, 1, flag);
if (flag->alignment_sign == '-')
print_right_allignment(lenght_of_hexadecimal, flag);
}