-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_tetri.c
70 lines (65 loc) · 1.63 KB
/
create_tetri.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* create_tetri.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tduval <tduval@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/20 03:56:08 by tduval #+# #+# */
/* Updated: 2018/11/20 04:02:56 by tduval ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdlib.h>
static char ***fill_tetri(char ***tetri, char *str)
{
int i;
int j;
int k;
int l;
i = 0;
l = 0;
while (tetri[i])
{
j = -1;
while (++j < 4)
{
k = -1;
while (++k < 4)
{
tetri[i][j][k] = str[l];
l++;
}
l++;
}
l++;
i++;
}
free(str);
return (tetri);
}
char ***create_tetri(char *str, int t)
{
char ***tetri;
int d;
int i;
int j;
d = 0;
i = 0;
if (!(tetri = (char ***)malloc(sizeof(char **) * (t + 1))))
return (0);
while (i < t)
{
j = 0;
if (!(tetri[i] = (char **)malloc(sizeof(char *) * 4)))
return (0);
while (j < 4)
{
if (!(tetri[i][j] = (char *)malloc(sizeof(char) * 4)))
return (0);
j++;
}
i++;
}
tetri[i] = 0;
return (tetri = fill_tetri(tetri, str) ? tetri : 0);
}