-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfdf_map_utils.c
87 lines (77 loc) · 1.99 KB
/
fdf_map_utils.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* fdf_map_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fvonsovs <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/14 16:44:13 by fvonsovs #+# #+# */
/* Updated: 2023/03/20 17:52:29 by fvonsovs ### ########.fr */
/* */
/* ************************************************************************** */
#include "fdf.h"
/*
// test function, will print contents of map array
int test_map_read(t_map *map)
{
int i, j;
printf("Height: %d\n", map->height);
printf("Width: %d\n", map->width);
printf("Z Max: %d\n", map->z_max);
printf("Z Min: %d\n", map->z_min);
printf("Array:\n");
for (i = 0; i < map->height; i++)
{
for (j = 0; j < map->width; j++)
{
printf("%i ", map->array[i][j]);
}
printf("\n");
}
return (0);
}
*/
// initializes map for usage
t_map *map_init(void)
{
t_map *map;
map = (t_map *)malloc(sizeof(t_map));
if (!map)
you_fucked_up("Error allocating map in map_init");
map->height = 0;
map->width = 0;
map->array = NULL;
map->z_max = 0;
map->z_min = 0;
return (map);
}
// does exactly what its called
void free_map_array(t_map *map)
{
int i;
i = 0;
while (i < map->height)
{
free(map->array[i]);
i++;
}
free(map->array);
map->array = NULL;
map->height = 0;
map->width = 0;
map->z_max = 0;
map->z_min = 0;
free(map);
}
// will free array of strings created by ft_split
void free_split(char **str)
{
int i;
i = 0;
while (str[i])
{
free(str[i]);
i++;
}
free(str);
}