/
tool.c
75 lines (65 loc) · 1.64 KB
/
tool.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* tool.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: baalbane <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/05/20 13:27:11 by baalbane #+# #+# */
/* Updated: 2016/05/20 13:48:19 by baalbane ### ########.fr */
/* */
/* ************************************************************************** */
#include "fillit.h"
int getsquare(t_list *start)
{
int i;
i = 1;
while ((start = start->next))
i++;
if (i > 26)
return (0);
i = ft_sqrt(i * 4);
return (i);
}
int reset(t_list *actuel, int nbr)
{
actuel->coord[0] = nbr;
actuel->coord[1] = nbr;
return (1);
}
int ft_strlen(char *str)
{
int i;
i = 0;
while (str[i])
i++;
return (i);
}
int **taballoc(int size)
{
int **tab;
int i;
i = 0;
tab = malloc(sizeof(int*) * (size + 1));
while (i < size)
{
tab[i] = malloc(sizeof(int) * 2);
tab[i][0] = -20;
tab[i][1] = -20;
i++;
}
tab[i] = malloc(sizeof(int) * 2);
tab[i][0] = -40;
tab[i][1] = -40;
return (tab);
}
int freetab(int **tab, int nbr)
{
int i;
i = 0;
while (tab[i][0] != -40)
free(tab[i++]);
free(tab[i]);
free(tab);
return (nbr);
}