-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strtrim.c
31 lines (28 loc) · 1.2 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: yjouaoud <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/04/12 21:28:27 by yjouaoud #+# #+# */
/* Updated: 2019/04/13 15:26:25 by yjouaoud ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strtrim(char const *s)
{
int i;
int j;
i = 0;
if (!s)
return (NULL);
while (s[i] == ' ' || s[i] == '\n' || s[i] == '\t')
i++;
if (s[i] == '\0')
return (ft_strnew(0));
j = (int)ft_strlen(s) - 1;
while (s[j] == ' ' || s[j] == '\n' || s[j] == '\t')
j--;
return (ft_strsub(s, i, j - i + 1));
}