-
Notifications
You must be signed in to change notification settings - Fork 0
/
read_map.c
71 lines (64 loc) · 1.82 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
62
63
64
65
66
67
68
69
70
71
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* read_map.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: oexall <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/06/16 12:45:48 by oexall #+# #+# */
/* Updated: 2016/06/17 06:59:49 by oexall ### ########.fr */
/* */
/* ************************************************************************** */
#include "wolf3d.h"
static int ft_get_width(char *line)
{
int i;
i = 0;
while (*line)
{
if (ft_isdigit(*line))
i++;
line++;
}
return (i);
}
void ft_print_array(int **array, t_mapinfo *map)
{
int i;
int j;
i = 0;
while (i < map->lines)
{
j = 0;
while (j < map->width)
{
ft_printf("|%d| ", array[i][j]);
j++;
}
ft_printf("\n");
i++;
}
}
int **get_array(t_mapinfo *map)
{
int **array;
int i;
int j;
i = -1;
map->width = ft_get_width(map->map[0]);
if (!(array = (int **)malloc(sizeof(int *) * map->lines)))
ft_puterror("get_array: Failed to malloc first lvl of array.");
while (++i < map->width)
if (!(*(array + i) = (int *)malloc(sizeof(int *) * map->width)))
ft_puterror("get_array: Failed to malloc second lvl of array");
i = 0;
while (i < map->lines)
{
j = -1;
while (++j < map->width)
array[i][j] = ft_atoi(ft_strsplit(map->map[i], ',')[j]);
i++;
}
ft_print_array(array, map);
return (array);
}