-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_create_grid.c
More file actions
53 lines (48 loc) · 1.51 KB
/
ft_create_grid.c
File metadata and controls
53 lines (48 loc) · 1.51 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_create_grid.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: akaseris <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/12/04 19:40:53 by akaseris #+# #+# */
/* Updated: 2017/12/20 11:04:41 by jszabo ### ########.fr */
/* */
/* ************************************************************************** */
#include "fillit.h"
static char *ft_str_grid(char *grid, int total, int i)
{
int c;
c = 0;
while (c < total + i)
{
grid[c] = ((c + 1) % (i + 1) == 0 && c) ? '\n' : '.';
c++;
}
grid[c] = '\0';
return (grid);
}
char **ft_create_grid(int pieces, int inc)
{
int total;
int i;
char *grid;
char **tabgrid;
total = pieces * 4;
i = 1;
while (!(total / i == i && total % i == 0))
{
if (i == total / 2)
{
total++;
i = 0;
}
i++;
}
total = (i + inc) * (i + inc);
i = i + inc;
grid = (char*)malloc(sizeof(*grid) * (total + i + 1));
tabgrid = ft_strsplit(ft_str_grid(grid, total, i), '\n');
free(grid);
return (tabgrid);
}