-
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.25 KB
/
ft_strtrim.c
File metadata and controls
33 lines (30 loc) · 1.25 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: nhennigh <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/02/12 18:35:08 by nhennigh #+# #+# */
/* Updated: 2019/02/14 19:49:06 by nhennigh ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strtrim(char const *s)
{
char *str;
int start;
int end;
if (!s)
return (NULL);
start = 0;
while (s[start] && ft_iswspace(s[start]))
start++;
end = ft_strlen(&s[start]) - 1;
while (s[start] && ft_iswspace(s[start + end]))
end--;
if (!(str = ft_strnew(end + 1)))
return (NULL);
ft_strncpy(str, (s + start), (end + 1));
return (str);
}