aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharles <sircharlesaze@gmail.com>2020-05-08 13:40:45 +0200
committerCharles <sircharlesaze@gmail.com>2020-05-08 13:40:45 +0200
commitb5124347359833fcde33452978c62133879c6c9e (patch)
tree0283c96661b50d13c1bbfb66c8101a603c44111f
parenta3c962abbcdae671b886c4c76ddb9bb8ac27c958 (diff)
downloadlibft-b5124347359833fcde33452978c62133879c6c9e.tar.gz
libft-b5124347359833fcde33452978c62133879c6c9e.tar.bz2
libft-b5124347359833fcde33452978c62133879c6c9e.zip
Fixed bug in ft_split
-rw-r--r--include/libft_str.h3
-rw-r--r--src/str/ft_split.c14
2 files changed, 4 insertions, 13 deletions
diff --git a/include/libft_str.h b/include/libft_str.h
index d65c90f..a373e86 100644
--- a/include/libft_str.h
+++ b/include/libft_str.h
@@ -6,7 +6,7 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/01/31 10:39:22 by cacharle #+# #+# */
-/* Updated: 2020/02/28 12:09:56 by cacharle ### ########.fr */
+/* Updated: 2020/05/08 13:39:12 by charles ### ########.fr */
/* */
/* ************************************************************************** */
@@ -16,6 +16,7 @@
# include <stddef.h>
# include "libft_ctype.h"
# include "libft_mem.h"
+# include "libft_util.h"
typedef enum
{
diff --git a/src/str/ft_split.c b/src/str/ft_split.c
index 6fb5964..0cb08e4 100644
--- a/src/str/ft_split.c
+++ b/src/str/ft_split.c
@@ -6,7 +6,7 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/10/17 08:29:02 by cacharle #+# #+# */
-/* Updated: 2019/11/20 04:08:27 by cacharle ### ########.fr */
+/* Updated: 2020/05/08 13:39:31 by charles ### ########.fr */
/* */
/* ************************************************************************** */
@@ -33,16 +33,6 @@ static size_t count_segment(char const *s, char c)
return (counter);
}
-static void *destroy_strs(char **strs)
-{
- if (strs == NULL)
- return (NULL);
- while (*strs != NULL)
- free(*strs++);
- free(strs);
- return (NULL);
-}
-
char **ft_split(char const *s, char c)
{
char **strs;
@@ -65,7 +55,7 @@ char **ft_split(char const *s, char c)
while (s[j + i] && s[j + i] != c)
i++;
if ((strs[tab_counter++] = ft_strndup(&s[j], i)) == NULL)
- return (destroy_strs(strs));
+ return (ft_split_destroy(strs));
j += i - 1;
}
strs[tab_counter] = NULL;