-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strtrim.c
executable file
·32 lines (29 loc) · 1.22 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strtrim.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: vportell <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/10/31 08:08:14 by vportell #+# #+# */
/* Updated: 2016/11/04 18:38:18 by vportell ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strtrim(char const *s)
{
int i;
char *str;
if (!s)
return (NULL);
while (*s && (*s == ' ' || *s == '\t' || *s == '\n'))
s++;
i = ft_strlen(s) - 1;
while (*s && (s[i] == ' ' || s[i] == '\t' || s[i] == '\n'))
i--;
str = ft_strnew(i + 1);
if (!str)
return (NULL);
ft_strncpy(str, s, i + 1);
return (str);
}