-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_strtrim.c
More file actions
30 lines (27 loc) · 1.18 KB
/
ft_strtrim.c
File metadata and controls
30 lines (27 loc) · 1.18 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strtrim.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lbiasuz <lbiasuz@student.42sp.org.br> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/04/18 22:47:23 by lbiasuz #+# #+# */
/* Updated: 2022/04/23 09:42:33 by lbiasuz ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strtrim(char const *s1, char const *set)
{
unsigned int i;
char *trim;
while (*s1 && ft_strchr(set, *s1))
s1++;
i = ft_strlen(s1);
while (i && ft_strchr(set, s1[i - 1]))
i--;
trim = malloc(i + 1);
if (!trim)
return (NULL);
ft_strlcpy(trim, s1, i + 1);
return (trim);
}