-
Notifications
You must be signed in to change notification settings - Fork 0
/
read_map.c
61 lines (56 loc) · 1.6 KB
/
read_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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* read_map.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: deleusis <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/02/23 18:03:35 by deleusis #+# #+# */
/* Updated: 2022/03/03 18:16:44 by deleusis ### ########.fr */
/* */
/* ************************************************************************** */
#include "so_long.h"
void read_map(char *map_name, t_prog *prog)
{
int fd;
int i;
char *str;
char *str2;
str2 = "init";
i = 0;
init_map (map_name, prog);
fd = open(map_name, O_RDONLY);
if (fd == -1)
error("Error to open\n");
while (str2)
{
str = get_next_line(fd);
str2 = ft_strtrim(str, "\n");
prog->map[i] = str2;
i++;
free(str);
}
close(fd);
}
void init_map(char *map_name, t_prog *prog)
{
int fd;
int i;
char *str;
str = "init";
i = 0;
fd = open(map_name, O_RDONLY);
if (fd == -1)
error("Error to open\n");
while (str)
{
str = get_next_line(fd);
free(str);
i++;
}
prog->map = malloc(sizeof(char *) * (i + 1));
if (!prog->map)
error("Malloc error\n");
prog->height = i;
close(fd);
}