-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strtrim.c
31 lines (29 loc) · 1.23 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strtrim.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: atabiti <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/11/16 11:17:22 by atabiti #+# #+# */
/* Updated: 2021/11/21 11:25:00 by atabiti ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strtrim(char const *s1, char const *set)
{
size_t len;
char *final;
if (!s1)
return (NULL);
while (*s1 && ft_strchr(set, *s1))
s1++;
len = ft_strlen(s1);
while (len > 0 && ft_strchr(set, s1[len -1]))
len--;
final = (char *) malloc (len + 1);
if (!final)
return (NULL);
ft_strlcpy(final, s1, len + 1);
return (final);
}