-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathft_strtrim.c
42 lines (39 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
42
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strtrim.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tbenoist <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2015/11/26 16:03:19 by tbenoist #+# #+# */
/* Updated: 2015/12/09 15:56:52 by tbenoist ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strtrim(char const *s)
{
char *trim;
int i;
int j;
int k;
i = 0;
j = 0;
k = 0;
while ((s[i] == ' ' || s[i] == '\n' || s[i] == '\t') && s[i])
i++;
if (!s[i])
return ("\0");
while (s[i + j + 1] != '\0')
j++;
while ((s[i + j] == ' ' || s[i + j] == '\n'
|| s[i + j] == '\t') && s[i + j])
j--;
if (!(trim = ft_strnew(j + 1)))
return (NULL);
while (k < j + 1)
{
trim[k] = s[i + k];
k++;
}
return (trim);
}