-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strtrim.c
33 lines (30 loc) · 1.23 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: hezzahir <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/05 20:08:05 by hezzahir #+# #+# */
/* Updated: 2018/11/06 07:54:44 by hezzahir ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strtrim(char const *s)
{
int start;
int end;
if (!s)
return (NULL);
start = 0;
end = ft_strlen(s) - 1;
while (s[start] == ' ' || s[start] == '\t' || s[start] == '\n')
{
start++;
}
while ((s[end] == ' ' || s[end] == '\t' || s[end] == '\n') && end > start)
{
end--;
}
return (ft_strsub(s, start, (end - start + 1)));
}