-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.c
63 lines (55 loc) · 1.66 KB
/
utils.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gwagner <gwagner@student.42wolfsburg.de +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/08/07 13:32:02 by gwagner #+# #+# */
/* Updated: 2024/08/10 16:16:56 by gwagner ### ########.fr */
/* */
/* ************************************************************************** */
#include "so_long.h"
void ft_free(char **str)
{
int i;
i = 0;
while (str[i])
i++;
while (i >= 0)
free(str[i--]);
free(str);
}
void ft_error2(char *msg, int fd, t_list **to_free)
{
perror(msg);
free_stack(to_free);
close(fd);
exit(EXIT_FAILURE);
}
void finish(t_data *data)
{
ft_printf("Well done! It took you %d moves!\n", data->movc + 1);
on_destroy(data);
}
void checkcol(int pos, t_data *data)
{
if (data->map[pos].type == 'C')
data->ccol++;
if (data->map[pos].type == '0' || data->map[pos].type == 'C')
data->movc++;
}
void checkmapname(char *mapname)
{
int i;
i = 0;
while (mapname[i])
i++;
i--;
if (mapname[i] != 'r' || mapname[i - 1] != 'e'
|| mapname[i - 2] != 'b' || mapname[i - 3] != '.')
{
perror("Error\nMapname is false!");
exit(EXIT_FAILURE);
}
}