-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strtrim.c
41 lines (38 loc) · 1.33 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strtrim.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lmartine <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/03/06 20:17:10 by lmartine #+# #+# */
/* Updated: 2018/03/06 20:26:40 by lmartine ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strtrim(char const *s)
{
char *temp;
int start;
unsigned int i;
if (!s)
return (NULL);
i = 0;
while (s[i] == ' ' || s[i] == '\n' || s[i] == '\t')
i++;
start = i;
if (s[start] == '\0')
{
temp = ft_strnew(0);
temp[0] = '\0';
return (temp);
}
while (s[i])
i++;
i--;
while (s[i] == ' ' || s[i] == '\n' || s[i] == '\t')
i--;
if (!(temp = (ft_strsub(s, start, i - start + 1))))
return (NULL);
return (temp);
}