-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strtrim.c
31 lines (28 loc) · 1.22 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strtrim.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: aelphias <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/09/29 13:25:53 by aelphias #+# #+# */
/* Updated: 2019/09/29 18:35:18 by aelphias ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strtrim(char const *s)
{
size_t i;
size_t len;
if (!s)
return (NULL);
i = 0;
len = ft_strlen(s) - 1;
while (s[i] == ' ' || s[i] == '\n' || s[i] == '\t')
i++;
if (s[i] == '\0')
return (ft_strdup(s + i));
while (s[len] == ' ' || s[len] == '\n' || s[len] == '\t')
len--;
return (ft_strsub(s, i, len - i + 1));
}