-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_flag_width_d.c
55 lines (49 loc) · 1.67 KB
/
ft_flag_width_d.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_flag_width_d.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: asibille <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/01/19 19:16:28 by asibille #+# #+# */
/* Updated: 2022/01/19 19:16:30 by asibille ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
static int ft_size_d(unsigned int n)
{
int sizeof_int;
sizeof_int = 1;
while (n > 9)
{
n /= 10;
++sizeof_int;
}
return (sizeof_int);
}
static void ft_put_width(int diff, t_conv_flags *fl, int *size)
{
while (diff > 0)
{
if (fl->zero && !(fl->minus) && !(fl->ispoint))
ft_putchar_count('0', 1, size);
else
ft_putchar_count(' ', 1, size);
--diff;
}
}
void ft_flag_width_d(size_t u, t_conv_flags *fl, int *size, int isneg)
{
int sizeof_int;
int diff;
if (fl->plus || fl->space)
isneg = 1;
sizeof_int = ft_size_d((unsigned int) u);
if (!(fl->point) && !u && (fl->ispoint))
diff = fl->width;
else if (fl->point > (sizeof_int))
diff = (fl->width) - ((fl ->point) + isneg);
else
diff = (fl->width) - (sizeof_int + isneg);
ft_put_width(diff, fl, size);
}