-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_sizes_num.c
97 lines (89 loc) · 2.53 KB
/
ft_sizes_num.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/* ************************************************************************** */
/* */
/* :::::::: */
/* ft_sizes_num.c :+: :+: */
/* +:+ */
/* By: greed <[email protected]> +#+ */
/* +#+ */
/* Created: 2019/11/16 16:20:16 by greed #+# #+# */
/* Updated: 2019/11/21 13:01:15 by greed ######## odam.nl */
/* */
/* ************************************************************************** */
#include "libft.h"
#include "libftprintf.h"
void ft_ll_num(t_conv *conv, va_list a_list, int *lv)
{
long long int num;
num = va_arg(a_list, long long int);
ft_conv_ll_int(conv, num);
if (conv->hassign && (conv->padzero || conv->left))
ft_putchar_c_fd(conv->sign, 1, lv);
if (conv->left)
{
ft_pad_width(conv->precision, conv->numlen, '0', lv);
if (conv->precision)
ft_llint_c_fd(num, lv);
}
if (!conv->left && conv->padzero)
ft_pad_width(conv->width, conv->precision + conv->hassign, '0', lv);
else
ft_pad_width(conv->width, conv->precision + conv->hassign, ' ', lv);
if (!conv->left)
{
if (conv->hassign && !conv->padzero)
ft_putchar_c_fd(conv->sign, 1, lv);
ft_pad_width(conv->precision, conv->numlen, '0', lv);
if (conv->precision)
ft_llint_c_fd(num, lv);
}
}
void ft_llint_c_fd(long long int num, int *lv)
{
long long int res;
long long int power;
res = num;
power = 1;
while (res / 10)
{
res /= 10;
power *= 10;
}
while (power)
{
if (num < 0)
ft_putchar_c_fd(('0' - num / power), 1, lv);
if (!(num < 0))
ft_putchar_c_fd(('0' + num / power), 1, lv);
num %= power;
power /= 10;
}
}
long long int ft_ll_nbr_size(long long int num)
{
long long int tmp;
long long int size;
tmp = num;
size = 0;
if (num == 0)
size++;
while (tmp)
{
tmp = tmp / 10;
size++;
}
return (size);
}
void ft_conv_ll_int(t_conv *conv, long long int num)
{
if (num < 0)
{
conv->hassign = 1;
conv->sign = '-';
}
conv->numlen = ft_ll_nbr_size(num);
if (conv->precision != -2)
conv->padzero = 0;
if (conv->precision == -2 ||
(conv->precision < conv->numlen && conv->precision != 0))
conv->precision = conv->numlen;
}