-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmap.c
66 lines (57 loc) · 879 Bytes
/
map.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
#include "fillit.h"
/*
** Use to find the smallest map possible to start with
*/
int ceil_sqrt(int tet_num)
{
int size;
size = 2;
while ((size * size) < tet_num)
size++;
return (size);
}
void print_map(t_map *map)
{
int i;
int j;
i = 0;
while (i < map->size)
{
j = 0;
while (j < map->size)
ft_putchar(map->arr[i][j++]);
map->arr[i][j] = '\0';
ft_putchar('\n');
i++;
}
}
t_map *new_map(int size)
{
t_map *new;
int i;
new = (t_map *)malloc(sizeof(t_map));
if (!new)
return (NULL);
new->size = size;
new->arr = (char **)malloc(sizeof(char*) * size + 5);
if (new->arr)
{
i = 0;
while (i < size)
new->arr[i++] = (char *)malloc(sizeof(char) * size + 5);
zero_map(new);
return (new);
}
return (NULL);
}
void free_map(t_map *map)
{
int i;
i = 0;
if (map)
{
while (i < map->size)
free(map->arr[i++]);
free(map);
}
}