-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strtrim.c
34 lines (31 loc) · 1.36 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strtrim.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jbadaire <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/03 16:00:38 by jbadaire #+# #+# */
/* Updated: 2023/10/03 16:00:38 by jbadaire ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
#include <stdlib.h>
char *ft_strtrim(char const *s1, char const *set)
{
int s_start;
int s_end;
char *mlc;
s_start = 0;
s_end = (int)ft_strlen(s1);
while (s_start < s_end && ft_strchr(set, s1[s_start]) != NULL)
s_start++;
while (s_end > s_start && ft_strchr(set, s1[s_end - 1]) != NULL)
s_end--;
mlc = malloc(sizeof(char) * s_end - s_start + 1);
if (!mlc)
return (NULL);
ft_memcpy(mlc, s1 + s_start, s_end - s_start);
mlc[s_end - s_start] = *"\0";
return (mlc);
}