-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathft_strtrim.c
38 lines (35 loc) · 1.37 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strtrim.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gamarcha <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/04/15 21:20:56 by gamarcha #+# #+# */
/* Updated: 2021/04/15 21:20:56 by gamarcha ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strtrim(char const *s1, char const *set)
{
char *str;
int start;
int end;
int i;
if (s1 == 0 || set == 0)
return (0);
start = 0;
while (s1[start] && ft_ischarset(s1[start], set))
start++;
end = ft_strlen(s1);
while (start < end && ft_ischarset(s1[end - 1], set))
end--;
str = (char *)malloc(end - start + 1);
if (str == 0)
return (0);
i = 0;
while (start < end)
str[i++] = s1[start++];
str[i] = 0;
return (str);
}