-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_checkflags.c
55 lines (51 loc) · 1.91 KB
/
ft_checkflags.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_checkflags.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fulldemo <fulldemo@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/11/30 12:03:56 by fulldemo #+# #+# */
/* Updated: 2019/12/13 16:52:59 by fulldemo ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
static t_flags *ft_checkflags_continue(t_flags *flags)
{
if (flags->nbr == 0 && *flags->ftm == '0' &&
flags->minus == false && flags->point == false)
{
flags->zero = true;
flags->nbr = ft_atoi((char *)flags->ftm);
}
else if (flags->point == true)
flags->aster = ft_atoi((char *)flags->ftm);
else
flags->nbr = ft_atoi((char *)flags->ftm);
while (*flags->ftm >= '0' && *flags->ftm <= '9')
flags->ftm++;
flags->ftm--;
return (flags);
}
void ft_checkflags(t_flags *flags, va_list lst)
{
int i;
i = 0;
flags->ftm++;
while (*flags->ftm == '-' || *flags->ftm == '0' || *flags->ftm == '.' ||
*flags->ftm == '*' || (*flags->ftm >= '0' && *flags->ftm <= '9'))
{
*flags->ftm == '-' ? flags->minus = true : 0;
*flags->ftm == '.' ? flags->point = true : 0;
if (*flags->ftm == '*')
{
if (flags->point == true)
flags->aster = va_arg(lst, int);
else
flags->nbr = va_arg(lst, int);
}
if (*flags->ftm >= '0' && *flags->ftm <= '9')
*flags = *ft_checkflags_continue(flags);
flags->ftm++;
}
}