-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strtrim.c
executable file
·33 lines (30 loc) · 1.23 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strtrim.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dcherend <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/03/29 13:46:51 by dcherend #+# #+# */
/* Updated: 2018/03/31 17:23:11 by dcherend ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strtrim(char const *s)
{
char *str;
int len;
if (s)
{
while (*s == ' ' || *s == '\t' || *s == '\n')
s++;
if (*s == '\0')
return (ft_strdup(""));
len = ft_strlen(s);
while (s[len - 1] == ' ' || s[len - 1] == '\n' || s[len - 1] == '\t')
len--;
str = ft_strsub(s, 0, len);
return ((char*)str);
}
return (NULL);
}