-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_printf_length.c
More file actions
62 lines (59 loc) · 1.81 KB
/
ft_printf_length.c
File metadata and controls
62 lines (59 loc) · 1.81 KB
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_printf_length.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mfrisby <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/07/11 13:12:24 by mfrisby #+# #+# */
/* Updated: 2017/07/11 13:12:26 by mfrisby ### ########.fr */
/* */
/* ************************************************************************** */
#include "libftprintf.h"
static int ft_printf_length2(t_env *e, char *format)
{
if (format[e->i] == 'h' && format[e->i + 1] && format[e->i + 1] != 'h')
{
e->m_h = 1;
e->i++;
}
else if (format[e->i + 1] && format[e->i] == 'h' && format[e->i + 1] == 'h')
{
e->m_hh = 1;
e->i += 2;
}
else if (format[e->i + 1] && format[e->i] == 'l' && format[e->i + 1] != 'l')
{
e->m_l = 1;
e->i++;
}
else
return (0);
return (1);
}
int ft_printf_length(t_env *e, char *format)
{
if ((format[e->i] == 'h' || format[e->i] == 'l' || format[e->i] == 'j' ||
format[e->i] == 'z') && !format[e->i + 1])
{
e->i++;
return (-1);
}
if (ft_printf_length2(e, format) == 1)
return (0);
if (format[e->i + 1] && format[e->i] == 'l' && format[e->i + 1] == 'l')
{
e->m_ll = 1;
e->i += 2;
}
else if (format[e->i] == 'j' && (e->i += 1))
e->m_j = 1;
else if (format[e->i] == 'z')
{
e->m_z = 1;
e->i++;
}
else
return (-1);
return (0);
}