-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathloop.c
74 lines (66 loc) · 1.96 KB
/
loop.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* loop.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: oltkache <oltkache@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/02/15 16:27:06 by oltkache #+# #+# */
/* Updated: 2018/02/16 16:08:07 by oltkache ### ########.fr */
/* */
/* ************************************************************************** */
#include "printf.h"
int *ft_intnew(int size)
{
int i;
int *new;
i = 0;
new = (int *)malloc(sizeof(int) * size);
while (i < size)
new[i++] = 0;
return (new);
}
int ft_ch(int c)
{
if (c == 1 && MB_CUR_MAX > 1)
return (1);
if (c == 0)
return (1);
return (0);
}
void ft_ch_loop(int **res, int p, char *str, int c)
{
int i;
i = 0;
while (p > 0)
{
if (str[i] == '-')
(*res)[0] = ft_increm_1(&p, &i);
else if (str[i] == 'l' && ft_ch(c) == 1)
(*res)[7] = ft_increm_1(&p, &i);
else if (str[i] == '#')
(*res)[6] = ft_increm_1(&p, &i);
else if (str[i] == '0')
(*res)[1] = ft_increm_1(&p, &i);
else if (str[i] == '+')
(*res)[2] = ft_increm_1(&p, &i);
else if (ft_isdigit(str[i]) && (*res)[3] == 0)
(*res)[3] = ft_increm_2(&str[i], &p, &i, 1);
else if (str[i] == '.')
(*res)[4] = ft_increm_2(&str[i + 1], &p, &i, 2);
else if (str[i] == ' ')
(*res)[5] = ft_increm_1(&p, &i);
else
ft_increm_1(&p, &i);
}
}
int *ft_loop(int p, char *str, int c)
{
int *res;
int i;
res = ft_intnew(8);
i = 0;
res[4] = -1;
ft_ch_loop(&res, p, str, c);
return (res);
}