-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_strtrim.c
More file actions
33 lines (30 loc) · 1.24 KB
/
ft_strtrim.c
File metadata and controls
33 lines (30 loc) · 1.24 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strtrim.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sconstab <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/05/30 09:44:06 by sconstab #+# #+# */
/* Updated: 2019/06/06 14:01:22 by sconstab ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strtrim(char const *s)
{
size_t i;
size_t e;
size_t it;
i = 0;
if (!s)
return (NULL);
while (s[i] && (s[i] == ' ' || s[i] == '\n' || s[i] == '\t'))
i++;
e = ft_strlen(s);
while (i < e && (s[e - 1] == ' ' || s[e - 1] == '\n' || s[e - 1] == '\t'))
e--;
if (e == i)
return (ft_strnew(1));
it = e - i;
return (ft_strsub(s, i, it));
}