-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmap.c
More file actions
53 lines (48 loc) · 1.44 KB
/
Copy pathmap.c
File metadata and controls
53 lines (48 loc) · 1.44 KB
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* map.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mnishimo <mnishimo@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/01/21 12:41:28 by mnishimo #+# #+# */
/* Updated: 2019/01/30 18:38:57 by mnishimo ### ########.fr */
/* */
/* ************************************************************************** */
#include "player.h"
char **init_map(int x, int y, char flag)
{
char **ret;
int i;
if (x <= 0 || y <= 0
|| (ret = (char **)malloc((y + 1) * sizeof(char *))) == NULL)
return (NULL);
ft_bzero(ret, sizeof(char *) * (y + 1));
i = 0;
while (i < y)
{
if ((ret[i] = ft_strnew(x)) == NULL)
break ;
i++;
}
if (i != y)
del_map(ret);
if (flag == 'b' && cp_board(x, y, ret) == NULL)
{
del_map(ret);
return (NULL);
}
return (ret);
}
void del_map(char **map)
{
int i;
i = 0;
while (map[i] != NULL)
{
free(map[i]);
i++;
}
free(map);
map = NULL;
}