-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strtrim.c
31 lines (28 loc) · 1.21 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strtrim.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: kacoulib <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/23 15:41:07 by kacoulib #+# #+# */
/* Updated: 2016/12/06 17:16:49 by kacoulib ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strtrim(char const *s)
{
int j;
if (!s)
return (NULL);
while (*s == ' ' || *s == '\n' || *s == '\t')
s++;
if (*s == '\0')
return (ft_strdup(""));
j = ft_strlen(s);
if (j == 0)
return (ft_strdup(""));
while (s[j - 1] == ' ' || s[j - 1] == '\n' || s[j - 1] == '\t')
j--;
return (ft_strsub(s, 0, j));
}