-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflag7.c
73 lines (66 loc) · 2.19 KB
/
flag7.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
72
73
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* flag7.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: abello-r <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/03/05 17:00:30 by abello-r #+# #+# */
/* Updated: 2020/03/05 17:00:32 by abello-r ### ########.fr */
/* */
/* ************************************************************************** */
#include "libftprintf.h"
size_t ft_lenhex_p(unsigned long nb)
{
size_t count;
count = 0;
if (nb == 0)
{
count++;
return (count);
}
if (nb < 0)
{
nb *= -1;
count++;
}
while (nb > 0)
{
nb = nb / 16;
count++;
}
return (count);
}
void ft_help(int space, t_printf *format, int nb, char *ch)
{
int flag;
while (space > 0 && format->tab != '-')
{
format->len_str += write(1, (format->zero_space != '0' ||
(format->dot == '.' && format->precision >= 0)) ? " " : "0", 1);
space--;
}
write(1, "0x", 2);
while (format->aux-- > 0)
format->len_str += write(1, "0", 1);
(format->dot == '.' && ch == NULL && format->precision == 0)
? 0 : ft_memorypointer(ch);
while (space-- > 0)
format->len_str += write(1, " ", 1);
format->len_str -= (format->dot == '.' && ch == NULL &&
format->precision == 0) ? 1 : 0;
}
void ft_display_pointer(t_printf *format, char *ch)
{
unsigned long nb;
int space;
int len;
len = ft_lenhex_p((unsigned long)ch) + 2;
format->len_str += nb = ft_lenhex_p((unsigned long)ch) + 2;
space = format->width - ((format->precision < len)
? len : format->precision);
space += (format->dot == '.' && nb == 0 && format->precision == 0) ? 1 : 0;
space += (ch == NULL && format->dot == '.') ? 1 : 0;
format->aux = format->precision - len + 2;
ft_help(space, format, nb, ch);
}