-
Notifications
You must be signed in to change notification settings - Fork 0
/
grid.c
executable file
·104 lines (90 loc) · 1.91 KB
/
grid.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
95
96
97
98
99
100
101
102
103
104
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* grid.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ismelich <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/11/28 10:47:19 by ismelich #+# #+# */
/* Updated: 2019/12/04 11:31:35 by ismelich ### ########.fr */
/* */
/* ************************************************************************** */
#include "fillit.h"
/*
** Returns the floored squareroot.
*/
int ft_floor_sqrt(int value)
{
int i;
while (value > 1)
{
i = 1;
while (i * i <= value)
{
if (i * i == value)
return (i);
i++;
}
value++;
}
return (0);
}
/*
** Calculates the number of tetras
*/
int num_tetra(char ***tetra)
{
int b;
b = 0;
while (tetra[b] != 0)
b++;
return (b);
}
/*
** Creates a square matrix filled with dots,
** every row is zero terminated, and last row is equal to NULL.
*/
char **gen_row(int m, int n, char c)
{
int i;
int j;
char **row;
i = 0;
j = 0;
row = (char**)malloc(sizeof(char*) * (n + 1));
while (i < n)
{
row[i] = (char*)malloc(sizeof(char) * (m + 1));
while (j < m)
row[i][j++] = c;
row[i][j] = 0;
j = 0;
i++;
}
row[i] = NULL;
return (row);
}
int **free_row(char **row)
{
int i;
i = 0;
while (row[i] != 0)
{
free(row[i]);
i++;
}
free(row);
row = NULL;
return (0);
}
int print_row(char **row)
{
int i;
i = 0;
while (row[i] != 0)
{
ft_putendl(row[i]);
i++;
}
return (0);
}