-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_strtrim.c
More file actions
35 lines (32 loc) · 1.32 KB
/
ft_strtrim.c
File metadata and controls
35 lines (32 loc) · 1.32 KB
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strtrim.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mtacnet <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/13 14:29:56 by mtacnet #+# #+# */
/* Updated: 2016/12/17 13:48:25 by mtacnet ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strtrim(char const *s)
{
unsigned int i;
unsigned int j;
unsigned int len;
if (!s)
return (NULL);
i = 0;
j = ft_strlen(s) - 1;
while ((s[i] == ' ' || s[i] == '\n' || s[i] == '\t') && s[i])
i++;
if (!(s[i]))
return (ft_strsub(s, i, 0));
while ((s[j] == ' ' || s[j] == '\n' || s[j] == '\t') && j > 0)
j--;
if (!i && j == (ft_strlen(s) - 1))
return (ft_strdup(s));
len = j - i;
return (ft_strsub(s, i, len + 1));
}