-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_printx.c
67 lines (61 loc) · 1.77 KB
/
ft_printx.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
/* ************************************************************************** */
/* */
/* :::::::: */
/* ft_printx.c :+: :+: */
/* +:+ */
/* By: novan-ve <novan-ve@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2019/12/27 16:07:12 by novan-ve #+# #+# */
/* Updated: 2019/12/27 16:09:35 by novan-ve ######## odam.nl */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
void ft_printx3(t_print *p, int x)
{
int i;
i = 0;
if (x == 0)
if (p->just == 'l')
while (i < p->tmpwidth - p->tmplen && i < p->tmpwidth - p->prec)
{
p->len++;
ft_putchar_fd(p->padchar, 1);
i++;
}
if (x == 1)
if (p->just == 'r')
while (i < p->tmpwidth - p->tmplen && i < p->tmpwidth - p->prec)
{
p->len++;
ft_putchar_fd(p->padchar, 1);
i++;
}
}
void ft_printx2(t_print *p)
{
int i;
ft_printx3(p, 0);
i = 0;
while (i < (p->prec - p->tmplen))
{
p->len++;
ft_putchar_fd('0', 1);
i++;
}
ft_putstr_fd(p->hex, 1);
ft_printx3(p, 1);
}
void ft_printx(t_print *p, int x)
{
ft_dec_to_hex(p, va_arg(p->args, unsigned int), x, 16);
if (p->hex[0] == '\0' && p->prec != 0)
{
p->hex[0] = '0';
p->hex[1] = '\0';
p->tmplen = 1;
}
if (p->tmplen < p->tmpwidth || p->prec != -1)
ft_printx2(p);
else
ft_putstr_fd(p->hex, 1);
}