-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strtrim.c
47 lines (43 loc) · 1.5 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
43
44
45
46
47
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strtrim.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sde-silv <sde-silv@student.42berlin.de> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/06/06 10:59:37 by sde-silv #+# #+# */
/* Updated: 2023/06/12 14:46:20 by sde-silv ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
/*
char *ft_strchr(const char *s, int c);
size_t ft_strlcpy(char *dst, const char *src, size_t size);
*/
char *ft_strtrim(char const *s1, char const *set)
{
size_t start;
size_t end;
char *ptr;
ptr = 0;
start = 0;
end = ft_strlen(s1) - 1;
while (s1[start] && ft_strchr(set, s1[start]))
start ++;
while (end + 1 > start && ft_strchr(set, s1[end]))
end --;
ptr = (char *)malloc(sizeof(char) * (end - start + 2));
if (ptr)
ft_strlcpy(ptr, (s1 + start), (end - start + 2));
return (ptr);
}
/*
int main(void)
{
char *ptr;
ptr = ft_strtrim("", "");
write(1, ptr, ft_strlen(ptr));
free (ptr);
return (0);
}
*/