-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strtrim.c
executable file
·36 lines (33 loc) · 1.31 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strtrim.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: akharrou <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/02/19 07:25:36 by akharrou #+# #+# */
/* Updated: 2019/04/30 11:05:08 by akharrou ### ########.fr */
/* */
/* ************************************************************************** */
#include "../Includes/ctype_42.h"
#include "../Includes/stdlib_42.h"
#include "../Includes/string_42.h"
char *ft_strtrim(char const *s, unsigned char c)
{
int last;
int first;
char *trimmed;
if (s)
{
first = 0;
while (s[first] && c == s[first])
++first;
last = ft_strlen(s) - 1;
while (last > 0 && c == s[last])
--last;
trimmed = ft_strndup(s + first, last - first);
free((void *)s);
return (trimmed);
}
return (NULL);
}