From a0f2bd93b7c4f85d0322752492531311ada0a3ec Mon Sep 17 00:00:00 2001 From: Jack Halford Date: Thu, 16 Feb 2017 11:43:31 +0100 Subject: [PATCH] strtrim fix --- libft/src/str/ft_strtrim.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/libft/src/str/ft_strtrim.c b/libft/src/str/ft_strtrim.c index 844ac335..22d17250 100644 --- a/libft/src/str/ft_strtrim.c +++ b/libft/src/str/ft_strtrim.c @@ -15,16 +15,13 @@ char *ft_strtrim(char const *s) { char *out; - size_t size; + char *last; + while (*s && FT_WS(*s)) + s++; out = ft_strdup(s); - while (*out && FT_WS(*out)) - out++; - size = ft_strlen(out); - while (size - 1 && FT_WS(out[size - 1])) - { - size--; - out[size] = '\0'; - } + last = out + ft_strlen(out) - 1; + while (last > out && FT_WS(*last)) + *last-- = 0; return (out); }