-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_strtrim.c
More file actions
34 lines (31 loc) · 1.22 KB
/
ft_strtrim.c
File metadata and controls
34 lines (31 loc) · 1.22 KB
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: rcappend <rcappend@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2020/11/02 11:42:06 by rcappend #+# #+# */
/* Updated: 2021/11/03 14:23:37 by rcappend ######## odam.nl */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strtrim(char const *s1, char const *set)
{
char *ret;
size_t len;
if (!s1)
return (NULL);
len = ft_strlen(s1);
while (ft_strchr(set, s1[len - 1]) != NULL && len > 1)
len--;
while (ft_strchr(set, *s1) != NULL && len > 0)
{
s1++;
len--;
}
ret = ft_substr(s1, 0, len);
if (!ret)
return (NULL);
return (ret);
}