-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathft_printf_flags.c
80 lines (75 loc) · 1.98 KB
/
ft_printf_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
71
72
73
74
75
76
77
78
79
80
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_printf_flags.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mzomeno- <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/01/09 12:41:26 by mzomeno- #+# #+# */
/* Updated: 2020/01/09 13:16:58 by mzomeno- ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
t_flags *initialize(t_flags *s)
{
s->zero = 0;
s->minus = 0;
s->width = 0;
s->precision = -1;
return (s);
}
void handle_flags(char *format, t_flags *s, int *it)
{
if (format[*it] == '0' && s->zero == 0)
{
s->zero = 1;
(*it)++;
}
else if (format[*it] == '-')
{
s->minus = 1;
(*it)++;
}
else
return ;
}
void handle_precision(char *format, t_flags *s, int *it)
{
if (format[*it] == '.' && s->precision == -1)
{
s->precision = 0;
(*it)++;
if (format[*it] == '*')
{
s->precision = va_arg(s->args, int);
(*it)++;
}
if ('0' <= format[*it] && format[*it] <= '9')
{
s->precision = format[*it] - '0';
(*it)++;
while ('0' <= format[*it] && format[*it] <= '9')
{
s->precision = s->precision * 10 + format[*it] - '0';
(*it)++;
}
}
}
else
return ;
}
void handle_width(char *format, t_flags *s, int *it)
{
if ('0' <= format[*it] && format[*it] <= '9')
{
s->width = format[*it] - '0';
(*it)++;
while ('0' <= format[*it] && format[*it] <= '9')
{
s->width = (s->width * 10) + (format[*it] - '0');
(*it)++;
}
}
else
return ;
}