-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strtrim.c
42 lines (39 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
37
38
39
40
41
42
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strtrim.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: knzeng-e <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/03/21 20:21:57 by knzeng-e #+# #+# */
/* Updated: 2016/03/31 17:07:57 by knzeng-e ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strtrim(char const *s)
{
char *output;
int i;
int start;
int cpt;
if (!s)
return (NULL);
i = 0;
while (ft_isspace(s[i]))
i++;
if (!(s[i]))
return (ft_strdup(""));
start = i;
while (s[i])
i++;
while (ft_isspace(s[i - 1]))
i--;
if ((output = (char *)malloc(sizeof(char) * (i - start) + 1)))
{
cpt = 0;
while (start < i)
output[cpt++] = s[start++];
output[cpt] = '\0';
}
return (output);
}