-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strtrim.c
34 lines (31 loc) · 1.28 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strtrim.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jlinarez <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/21 14:03:25 by jlinarez #+# #+# */
/* Updated: 2024/03/21 14:24:02 by jlinarez ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strtrim(char const *s1, char const *set)
{
size_t i;
size_t j;
char *str;
if (s1 == NULL || set == NULL)
return (NULL);
i = 0;
while (s1[i] && ft_strchr(set, s1[i]))
i++;
j = ft_strlen(s1);
while (j > i && ft_strchr(set, s1[j - 1]))
j--;
str = (char *)malloc(sizeof(char) * (j - i + 1));
if (str == NULL)
return (NULL);
ft_strlcpy(str, s1 + i, j - i + 1);
return (str);
}