-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpath.c
More file actions
50 lines (44 loc) · 1.47 KB
/
path.c
File metadata and controls
50 lines (44 loc) · 1.47 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* path.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rahidalg <rahidalg@student.42madrid.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/01/18 12:55:36 by rahidalg #+# #+# */
/* Updated: 2025/01/18 12:55:54 by rahidalg ### ########.fr */
/* */
/* ************************************************************************** */
#include "so_long.h"
void alloc_map(char **map, char *line, int row)
{
map[row] = malloc((ft_strlen(line) + 1) * sizeof(char));
}
void free_map(char **map)
{
int i;
i = 0;
while (map[i])
{
free(map[i]);
i++;
}
free(map);
}
void valid_path(char *dir, t_mlx_data *data)
{
int fd;
char **map;
fd = open(dir, O_RDONLY);
map = malloc((data->game.win.height + 1) * sizeof(char *));
read_map(fd, map, data);
close(fd);
free_map(map);
if (data->counter != data->coins || data->is_exit != 1)
{
ft_printf("Error\nThe map cannot be completed!\n");
close_mlx(data);
exit(1);
}
set_data(data);
}