-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strtrim.c
38 lines (35 loc) · 1.38 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
/* ************************************************************************** */
/* LE - / */
/* / */
/* ft_strtrim2.c .:: .:/ . .:: */
/* +:+:+ +: +: +:+:+ */
/* By: thperchi <marvin@le-101.fr> +:+ +: +: +:+ */
/* #+# #+ #+ #+# */
/* Created: 2018/07/23 02:37:29 by thperchi #+# ## ## #+# */
/* Updated: 2018/10/16 15:52:54 by thperchi ### #+. /#+ ###.fr */
/* / */
/* / */
/* ************************************************************************** */
#include "libft.h"
char *ft_strtrim(char const *s)
{
char *str;
int x;
int y;
int z;
if (!s)
return (NULL);
x = 0;
y = ft_strlen(s);
z = 0;
while (s[x] == ' ' || s[x] == '\n' || s[x] == '\t')
x++;
while (s[y] == ' ' || s[y] == '\n' || s[y] == '\t' || s[y] == '\0')
y--;
if (!(str = (char *)malloc(sizeof(char) * ((ft_strlen(s)) + 2))))
return (NULL);
while (x <= y)
str[z++] = s[x++];
str[z] = '\0';
return (str);
}