aboutsummaryrefslogtreecommitdiff
path: root/ft_split_strict.c
diff options
context:
space:
mode:
authorCharles <sircharlesaze@gmail.com>2020-02-05 01:29:21 +0100
committerCharles <sircharlesaze@gmail.com>2020-02-05 01:29:21 +0100
commit19964c7a382bcc5c0f09b1233b54b559c44e3a28 (patch)
treea1176b33125cc3c405d37827ebaaf329904516a1 /ft_split_strict.c
parentf078f191515d0fc65340a8722fad14f3de679d7b (diff)
downloadlibft-19964c7a382bcc5c0f09b1233b54b559c44e3a28.tar.gz
libft-19964c7a382bcc5c0f09b1233b54b559c44e3a28.tar.bz2
libft-19964c7a382bcc5c0f09b1233b54b559c44e3a28.zip
fixing ft_split_strict
Diffstat (limited to 'ft_split_strict.c')
-rw-r--r--ft_split_strict.c14
1 files changed, 6 insertions, 8 deletions
diff --git a/ft_split_strict.c b/ft_split_strict.c
index 9964f4c..69d2220 100644
--- a/ft_split_strict.c
+++ b/ft_split_strict.c
@@ -6,7 +6,7 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/02/04 05:20:26 by cacharle #+# #+# */
-/* Updated: 2020/02/04 05:21:29 by cacharle ### ########.fr */
+/* Updated: 2020/02/04 23:27:46 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -22,7 +22,7 @@ static size_t count_segment(char const *s, char c)
while (s[++i])
if (s[i] == c)
counter++;
- return (counter);
+ return (counter + 1);
}
static char *ft_strndup(const char *s1, size_t n)
@@ -53,7 +53,7 @@ static void *destroy_strs(char **strs)
return (NULL);
}
-char **ft_split(char const *s, char c)
+char **ft_split_strict(char const *s, char c)
{
char **strs;
size_t tab_counter;
@@ -63,20 +63,18 @@ char **ft_split(char const *s, char c)
if (s == NULL)
return (NULL);
tab_counter = count_segment(s, c);
- if ((strs = (char**)malloc(sizeof(char*) * (tab_counter + 1))) == NULL)
+ if ((strs = (char**)malloc(sizeof(char*) * (tab_counter + 20))) == NULL)
return (NULL);
tab_counter = 0;
j = -1;
- while (s[++j])
+ while (s[++j] != '\0')
{
- if (s[j] == c)
- continue ;
i = 0;
while (s[j + i] && s[j + i] != c)
i++;
if ((strs[tab_counter++] = ft_strndup(&s[j], i)) == NULL)
return (destroy_strs(strs));
- j += i - 1;
+ j += i;
}
strs[tab_counter] = NULL;
return (strs);