-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmap.c
63 lines (56 loc) · 1.61 KB
/
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* map.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: afrancoi <afrancoi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/01/30 12:34:15 by afrancoi #+# #+# */
/* Updated: 2019/03/04 10:00:16 by afrancoi ### ########.fr */
/* */
/* ************************************************************************** */
#include "fillit.h"
#include <stdlib.h>
t_map *ft_new_map(int size)
{
t_map *map;
int nb;
nb = size;
if (!(map = (t_map*)ft_memalloc(sizeof(t_map))))
return (0);
map->size = size;
if (!(map->tab = (char**)ft_memalloc(sizeof(char*) * size)))
return (0);
while (nb--)
{
if (!(map->tab[nb] = (char*)ft_memalloc(sizeof(char) * size)))
return (0);
ft_memset(map->tab[nb], '.', size);
}
return (map);
}
void ft_free_map(t_map *map)
{
int size;
size = map->size;
while (size--)
{
free(map->tab[size]);
}
free(map->tab);
free(map);
}
void ft_print_map(t_map *map)
{
int x;
int y;
x = -1;
while (++x < map->size)
{
y = -1;
while (++y < map->size)
ft_putchar(map->tab[x][y]);
ft_putendl("");
}
ft_putendl("");
}