-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strtrim.c
61 lines (55 loc) · 1.59 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
49
50
51
52
53
54
55
56
57
58
59
60
61
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strtrim.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jkeuleya <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2014/11/09 13:07:07 by jkeuleya #+# #+# */
/* Updated: 2014/11/12 10:27:04 by jkeuleya ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdlib.h>
#include "libft.h"
#include "libft.h"
#include <stdlib.h>
static int ft_stri(char const *s, int i)
{
while ((s[i] == ' ') || (s[i] == '\n')
|| (s[i] == '\t') || (s[i] == '\0'))
i++;
return (i);
}
static int ft_strn(char const *s, int n)
{
while ((s[n] == ' ') || (s[n] == '\n')
|| (s[n] == '\t') || (s[n] == '\0'))
n--;
return (n);
}
char *ft_strtrim(char const *s)
{
char *str;
int i;
int j;
int n;
if (s)
{
j = 0;
i = 0;
n = ft_strlen(s);
if ((str = malloc(sizeof(char) * (ft_strlen(s) + 1))) == NULL)
return (NULL);
n = ft_strn(s, n);
i = ft_stri(s, i);
while (i <= n)
{
str[j] = s[i];
j++;
i++;
}
str[j] = '\0';
return (str);
}
return (NULL);
}