-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strtrim.c
35 lines (32 loc) · 1.27 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strtrim.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cfeliz-r <cfeliz-r@student.42madrid.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/19 10:27:07 by cfeliz-r #+# #+# */
/* Updated: 2024/03/19 10:27:13 by cfeliz-r ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strtrim(char const *s1, char const *set)
{
size_t i;
size_t j;
char *str;
str = 0;
if (s1 != 0 && set != 0)
{
i = 0;
j = ft_strlen(s1);
while (s1[i] && ft_strchr(set, s1[i]))
i++;
while (s1[j - 1] && ft_strchr(set, s1[j - 1]) && j > i)
j--;
str = (char *)malloc(sizeof(char) * (j - i + 1));
if (str)
ft_strlcpy(str, &s1[i], j - i + 1);
}
return (str);
}