-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfdf_read.c
56 lines (51 loc) · 1.58 KB
/
fdf_read.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* fdf_read.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: aillia <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/04/16 14:11:15 by aillia #+# #+# */
/* Updated: 2019/04/16 14:11:20 by aillia ### ########.fr */
/* */
/* ************************************************************************** */
#include "fdf.h"
void create_map(t_fdf *fdf, char ***arr)
{
int **map;
int i;
int j;
map = (int **)malloc(sizeof(int *) * fdf->rows + 1);
i = -1;
while (++i <= fdf->rows)
map[i] = (int *)malloc(sizeof(int ) * fdf->colums);
i = -1;
while (++i < fdf->rows)
{
j = -1;
while (++j < fdf->colums)
map[i][j] = ft_atoi(arr[i][j]);
}
fdf->map = map;
cleaner(&arr);
}
void read_me(int fd, t_fdf *fdf)
{
char *line;
char ***arr;
int i;
arr = (char ***)ft_memalloc(sizeof(char **) * (fdf->rows + 1));
i = -1;
while (get_next_line(fd, &line) == 1)
{
i++;
arr[i] = ft_strsplit(line, ' ');
free(line);
}
arr[++i] = NULL;
i = 0;
while (arr[0][i])
i++;
fdf->colums = i;
create_map(fdf, arr);
}