diff options
| author | Charles <sircharlesaze@gmail.com> | 2020-06-09 17:57:10 +0200 |
|---|---|---|
| committer | Charles <sircharlesaze@gmail.com> | 2020-06-09 17:57:10 +0200 |
| commit | 6fe30c97aad7a4a3564e7037d64a43edcb9a2162 (patch) | |
| tree | 5d36f19eb619811c93b852c5f5e04eb6fe12e85c /src/str | |
| parent | f1babc364b2507cb8999d3132941b056feac37cd (diff) | |
| download | libft-6fe30c97aad7a4a3564e7037d64a43edcb9a2162.tar.gz libft-6fe30c97aad7a4a3564e7037d64a43edcb9a2162.tar.bz2 libft-6fe30c97aad7a4a3564e7037d64a43edcb9a2162.zip | |
Added ft_dstrwrap, ft_splitf, fixing bug in ft_split
Diffstat (limited to 'src/str')
| -rw-r--r-- | src/str/ft_split.c | 14 | ||||
| -rw-r--r-- | src/str/ft_splitf.c | 22 |
2 files changed, 24 insertions, 12 deletions
diff --git a/src/str/ft_split.c b/src/str/ft_split.c index 6fb5964..b61b09f 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/06/09 17:14:58 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; diff --git a/src/str/ft_splitf.c b/src/str/ft_splitf.c new file mode 100644 index 0000000..2a1afab --- /dev/null +++ b/src/str/ft_splitf.c @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_splitf.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/06/09 17:45:52 by charles #+# #+# */ +/* Updated: 2020/06/09 17:47:17 by charles ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft_str.h" + +char **ft_splitf(char *s, char delim) +{ + char **ret; + + ret = ft_split(s, delim); + free(s); + return (ret); +} |
