-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strtrim.c
48 lines (44 loc) · 1.32 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
48
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strtrim.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: abassibe <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/24 16:33:55 by abassibe #+# #+# */
/* Updated: 2018/03/14 01:45:26 by abassibe ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
static int ft_isblank(int c)
{
if (c == ' ' || c == '\n' || c == '\t')
return (1);
return (0);
}
char *ft_strtrim(const char *str)
{
int i;
int j;
int k;
if (!str)
return (NULL);
i = 0;
while (ft_isblank(str[i]) == 1)
i++;
j = 0;
k = 0;
while (str[k] != '\0')
{
if (ft_isblank(str[k]) == 0)
{
k++;
j = k;
}
else
k++;
}
if (j == 0)
return (ft_strdup(""));
return (ft_strsub(str, i, j - i));
}