-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strstrip.c
executable file
·36 lines (33 loc) · 1.36 KB
/
ft_strstrip.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strstrip.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: akharrou <akharrou@student.42.us.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/05/19 10:43:30 by akharrou #+# #+# */
/* Updated: 2019/05/19 10:43:32 by akharrou ### ########.fr */
/* */
/* ************************************************************************** */
#include "../Includes/ctype_42.h"
#include "../Includes/stdlib_42.h"
#include "../Includes/string_42.h"
char *ft_strstrip(char const *s, char *charset)
{
int last;
int first;
char *stripped;
if (s)
{
first = 0;
while (s[first] && ft_ischarset(s[first], charset))
++first;
last = ft_strlen(s) - 1;
while (last >= 0 && ft_ischarset(s[last], charset))
--last;
stripped = ft_strndup(s + first, (last + 1) - first);
free((void *)s);
return (stripped);
}
return (NULL);
}