-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strtrim.c
executable file
·47 lines (43 loc) · 1.41 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
42
43
44
45
46
47
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strtrim.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ngouy <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2014/11/06 14:57:54 by ngouy #+# #+# */
/* Updated: 2015/11/04 17:28:12 by ngouy ### ########.fr */
/* */
/* ************************************************************************** */
/*
** Return a new str fill with s without blank spaces at the beginin and
** the end of it.
*/
#include "libft.h"
char *ft_strtrim(char const *s)
{
char *ret;
int i;
int j;
i = 0;
j = 0;
if (!s)
return (NULL);
ret = ft_strnew(ft_strlen(s));
if (!ret)
return (NULL);
while (s[i] == ' ' || s[i] == '\n' || s[i] == '\t')
i++;
if (i == (int)ft_strlen(s))
return (ret);
while (s[i])
{
ret[j] = s[i];
j++;
i++;
}
j--;
while (ret[j] == ' ' || ret[j] == '\n' || ret[j] == '\t')
ret[j--] = '\0';
return (ret);
}