-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strtrim.c
42 lines (39 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
38
39
40
41
42
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strtrim.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ewilliam <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/02 15:24:22 by ewilliam #+# #+# */
/* Updated: 2016/12/09 11:49:05 by ewilliam ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strtrim(char const *s)
{
char *ptr;
char *optr;
size_t len;
len = 0;
if (s)
{
while (ft_isspace(*s))
s++;
if (!*s)
return (ft_strdup(""));
len = ft_strlen(s);
while (ft_isspace(s[len - 1]))
len--;
ptr = ft_strnew(len + 1);
if (ptr)
{
optr = ptr;
while (len--)
*ptr++ = *s++;
*ptr = '\0';
return (optr);
}
}
return (NULL);
}