-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strtrim.c
37 lines (34 loc) · 1.26 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strtrim.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: akdemir <[email protected] +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/07/09 20:42:56 by akdemir #+# #+# */
/* Updated: 2023/07/17 16:29:42 by akdemir ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strtrim(char const *s1, char const *set)
{
char *p;
size_t i;
size_t li;
i = 0;
if (!s1 || !set)
return (NULL);
while (s1[i] && ft_strchr(set, s1[i]))
i++;
li = ft_strlen(s1) -1;
while (ft_strchr(set, s1[li]) && li)
li--;
p = ft_substr(s1, i, li - i + 1);
return (p);
}
int main()
{
char *s1="ackifca";
char *set="ak";
printf("%s",ft_strtrim(s1,set));
}