-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.c
87 lines (80 loc) · 2.07 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jbadaire <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/03 10:24:01 by jbadaire #+# #+# */
/* Updated: 2023/10/14 16:21:39 by jbadaire ### ########.fr */
/* */
/* ************************************************************************** */
#include "so_long.h"
t_location find_element(t_world world, char type)
{
int pos_x;
int pos_y;
t_location location;
pos_x = 0;
pos_y = 0;
location.x = -1;
location.y = -1;
while (world.map[pos_y])
{
while (pos_x < (int) ft_strlen(world.map[0]))
{
if (world.map[pos_y][pos_x] == type)
{
location.x = ++pos_x;
location.y = ++pos_y;
return (location);
}
pos_x++;
}
pos_x = 0;
pos_y++;
}
return (location);
}
int count_element(t_world world, char type)
{
int pos_x;
int pos_y;
int count;
pos_x = 0;
pos_y = 0;
count = 0;
while (pos_y < world.length_y)
{
while (pos_x < (int) ft_strlen(world.map[0]))
{
if (world.map[pos_y][pos_x] == type)
count++;
pos_x++;
}
pos_x = 0;
pos_y++;
}
return (count);
}
t_boolean ft_endwith(char *src, char *pattern)
{
int pattern_size;
int src_size;
if (!pattern || !src)
return (_false);
pattern_size = (int) ft_strlen(pattern);
src_size = (int) ft_strlen(src);
if (pattern_size > src_size)
return (_false);
--pattern_size;
--src_size;
while (src_size > 0 && pattern_size > 0)
{
if (src[src_size] != pattern[pattern_size])
return (_false);
pattern_size--;
src_size--;
}
return (_true);
}