-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strtrim.c
33 lines (30 loc) · 1.18 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strtrim.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: nvienot <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/15 22:17:05 by nvienot #+# #+# */
/* Updated: 2018/11/21 17:50:44 by nvienot ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strtrim(char const *s)
{
int i;
int len;
i = 0;
if (!s)
return (NULL);
while (ft_iswhitespace(s[i]) == 1)
{
i++;
if (s[i] == '\0')
return (ft_strdup(""));
}
len = ft_strlen(s) - 1;
while (ft_iswhitespace(s[len]) == 1)
len--;
return (ft_strsub(s, i, len - i + 1));
}