-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strtrim.c
36 lines (33 loc) · 1.3 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strtrim.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: javellis <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/07 14:38:43 by javellis #+# #+# */
/* Updated: 2022/10/07 14:38:46 by javellis ### ########.fr */
/* */
/* ************************************************************************** */
#include"libft.h"
#include <stdlib.h>
char *ft_strtrim(char const *s1, char const *set)
{
size_t i;
size_t j;
char *str;
str = 0;
if (set != 0 && s1 != 0)
{
i = 0;
j = ft_strlen(s1);
while (ft_strchr(set, s1[i]) && s1[i])
i++;
while (ft_strchr(set, s1[j - 1]) && j > i && s1[j - 1])
j--;
str = (char *)malloc(sizeof(char) * (j - i + 1));
if (str)
ft_strlcpy(str, (char *)&s1[i], j - i + 1);
}
return (str);
}