-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strtrim.c
executable file
·40 lines (37 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strtrim.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: shillebr <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/05/29 09:46:36 by shillebr #+# #+# */
/* Updated: 2018/05/30 13:32:10 by shillebr ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strtrim(char const *s)
{
unsigned int i;
unsigned int j;
char *ret;
if (s)
{
i = 0;
j = ft_strlen(s) - 1;
while (s[i] == ' ' || s[i] == '\n' || s[i] == '\t')
i++;
if (s[i] == '\0')
{
ret = ft_strcpy(ft_memalloc(sizeof(char) * 2), "");
return (ret);
}
while (s[j] == ' ' || s[j] == '\n' || s[j] == '\t')
j--;
ret = ft_strsub(s, i, j - i + 1);
if (ret)
return (ret);
return (NULL);
}
return (NULL);
}