-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_conv_hexa.c
61 lines (56 loc) · 1.89 KB
/
ft_conv_hexa.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* convhexa.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: isousa <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/03/29 12:50:31 by isousa #+# #+# */
/* Updated: 2021/03/29 12:50:41 by isousa ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
int ft_printhexa(t_flags s_fl, char *hexa)
{
int counter;
counter = 0;
if (s_fl.dot >= 0)
{
s_fl.width -= s_fl.dot;
counter += ft_convwidth(s_fl.width, 0, 0);
}
else
counter += ft_convwidth(s_fl.width, ft_strlen(hexa), s_fl.zero);
if (s_fl.hiffen == 0)
{
if (s_fl.dot >= 0)
counter += ft_convwidth(s_fl.dot, ft_strlen(hexa), 1);
counter += ft_precision(hexa, ft_strlen(hexa));
}
return (counter);
}
int ft_convhexa(unsigned int num, int xtype, t_flags s_fl)
{
int counter;
char *hexa;
counter = 0;
if (num == 0 && s_fl.dot == 0)
{
counter += ft_convwidth(s_fl.width, 0, 0);
return (counter);
}
hexa = ft_unsigneditoa(num, 16);
if (xtype == 0)
hexa = ft_tolower(hexa);
if (s_fl.hiffen == 1)
{
if (s_fl.dot >= 0)
counter += ft_convwidth(s_fl.dot, ft_strlen(hexa), 1);
counter += ft_precision(hexa, ft_strlen(hexa));
}
if (s_fl.dot >= 0 && (s_fl.dot < ft_strlen(hexa)))
s_fl.dot = ft_strlen(hexa);
counter += ft_printhexa(s_fl, hexa);
free(hexa);
return (counter);
}