-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_read_map_file.c
61 lines (56 loc) · 1.57 KB
/
ft_read_map_file.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_read_map_file.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: prranges <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/01/29 11:54:06 by mbalman #+# #+# */
/* Updated: 2022/02/02 14:14:33 by prranges ### ########.fr */
/* */
/* ************************************************************************** */
#include "cub3d.h"
int ft_size_map(char **argv)
{
int size;
int end_file;
int fd;
char *str;
size = 0;
str = NULL;
end_file = 1;
fd = open(argv[1], O_RDONLY);
if (fd == -1)
perror("Error");
while (end_file)
{
end_file = get_next_line(fd, &str);
free(str);
size++;
}
close(fd);
return (size);
}
void ft_load_map(char **argv, char ***map, int i)
{
int fd;
int end_file;
int size;
char *str;
char **temp;
temp = NULL;
end_file = 1;
size = ft_size_map(argv);
temp = (char **)malloc(sizeof(char *) * (size + 1));
fd = open(argv[1], O_RDONLY);
while (end_file)
{
end_file = get_next_line(fd, &str);
temp[i] = str;
i++;
}
temp[i] = NULL;
i = 0;
*map = temp;
close(fd);
}