-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strtrim.c
42 lines (39 loc) · 1.3 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: moana <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/01/04 23:56:54 by moana #+# #+# */
/* Updated: 2018/01/17 20:49:27 by moana ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strtrim(char const *s)
{
int i;
int j;
int k;
char *tmp;
if (s)
{
i = 0;
j = ft_strlen((char *)s) - 1;
while (s[i] == ' ' || s[i] == '\n' || s[i] == '\t')
i++;
tmp = (char *)malloc(sizeof(char) * (j - i + 1));
while (s[j] == ' ' || s[j] == '\n' || s[j] == '\t')
j--;
k = 0;
while (i <= j)
{
tmp[k] = s[i];
i++;
k++;
}
tmp[k] = '\0';
return (tmp);
}
return (NULL);
}