-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunc.c
executable file
·94 lines (84 loc) · 2 KB
/
func.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* func.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: vportell <vportell@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/09 21:00:29 by stati #+# #+# */
/* Updated: 2016/11/13 11:09:43 by vportell ### ########.fr */
/* */
/* ************************************************************************** */
#include "fillit.h"
t_piece *ft_piece_to_letter(t_piece *piece, char *av, unsigned int check)
{
t_piece *pieces;
char str[SIZE + 1];
unsigned int i;
int fd;
int ret;
i = 0;
piece = 0;
fd = open(av, O_RDONLY);
while ((ret = read(fd, str, SIZE + 1)))
{
str[ret - 1] = '\0';
if (ret == 21)
check++;
storedash(&pieces, str, i);
i++;
}
close(fd);
return (pieces);
}
char **build_plan(unsigned int size)
{
unsigned int i;
char **board;
i = 0;
board = (char**)malloc(sizeof(char*) * (size + 1));
while (i < size)
{
board[i] = ft_strnew(size + 1);
board[i] = ft_memset(board[i], '.', size);
i++;
}
board[i] = 0;
return (board);
}
int square_finder(int n, int nb)
{
if (n * n > nb)
return (0);
if (n * n == nb)
return (n);
else
return (square_finder(n + 1, nb));
}
int count_piece(t_piece **blst)
{
t_piece *lst;
int i;
i = 0;
lst = *blst;
while (lst)
{
i++;
lst = lst->next;
}
return (i);
}
int give_size(t_piece *lst)
{
unsigned int size;
unsigned int i;
size = count_piece(&lst);
size *= 4;
i = 0;
while (!i)
{
i = square_finder(1, size);
size++;
}
return (i);
}