-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_flags.c
70 lines (63 loc) · 1.7 KB
/
ft_flags.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* flags.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: isousa <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/03/29 12:50:48 by isousa #+# #+# */
/* Updated: 2021/03/29 12:50:52 by isousa ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
t_flags ft_startflags(void)
{
t_flags s_fl;
s_fl.dot = -1;
s_fl.hiffen = 0;
s_fl.width = 0;
s_fl.star = 0;
s_fl.letter = 0;
s_fl.zero = 0;
return (s_fl);
}
int ft_dot(const char *format, va_list args, t_flags *s_fl, int i)
{
i++;
if (format[i] == '*')
{
s_fl->dot = va_arg(args, int);
i++;
}
else
{
s_fl->dot = 0;
while (ft_digit(format[i]))
{
s_fl->dot = (s_fl->dot * 10) + (format[i] - '0');
i++;
}
}
return (i);
}
void ft_hiffen(t_flags *s_fl)
{
s_fl->hiffen = 1;
s_fl->zero = 0;
}
void ft_star(va_list args, t_flags *s_fl)
{
s_fl->star = 1;
s_fl->width = va_arg(args, int);
if (s_fl->width < 0)
{
s_fl->hiffen = 1;
s_fl->width *= -1;
}
}
void ft_width(char c, t_flags *s_fl)
{
if (s_fl->star == 1)
s_fl->width = 0;
s_fl->width = (s_fl->width * 10) + (c - '0');
}