-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strtrim.c
42 lines (38 loc) · 1.41 KB
/
ft_strtrim.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strtrim.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ctacconi <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/25 16:26:50 by ctacconi #+# #+# */
/* Updated: 2024/01/31 16:22:22 by ctacconi ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
//eleimina los caracteres set de la s1(ppo y final)
char *ft_strtrim(char const *s1, char const *set)
{
char *ptr;
int start;
int end;
start = 0;
end = ft_strlen(s1);
if (!s1 || !set)
return (NULL);
while (ft_strchr(set, s1[start]) && start < end && s1[start])
{
start++;
}
while (ft_strchr(set, s1[end]) && end > start)
{
end--;
}
ptr = ft_substr(s1, start, end - start + 1);
return (ptr);
}
/*int main ()
{
printf("%s\n", ft_strtrim("papapacarolpapap","pa"));
printf("%s\n", ft_strtrim("", ""));
}*/