-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strtrim.c
34 lines (31 loc) · 1.29 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
34
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strtrim.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ccline <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/10/01 16:27:24 by ccline #+# #+# */
/* Updated: 2019/10/06 10:12:36 by ccline ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strtrim(char const *s)
{
unsigned int min;
unsigned int max;
min = 0;
if (s == NULL)
return (NULL);
while (s[min] && (s[min] == ' ' || s[min] == '\n' || s[min] == '\t'))
min++;
if (s[min] == '\0')
return (ft_strdup(s + min));
max = min;
while (s[max])
max++;
max -= 1;
while (s[max] == ' ' || s[max] == '\n' || s[max] == '\t')
max--;
return (ft_strsub(s, min, max - min + 1));
}