aboutsummaryrefslogtreecommitdiff
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
parentf078f191515d0fc65340a8722fad14f3de679d7b (diff)
downloadlibft-19964c7a382bcc5c0f09b1233b54b559c44e3a28.tar.gz
libft-19964c7a382bcc5c0f09b1233b54b559c44e3a28.tar.bz2
libft-19964c7a382bcc5c0f09b1233b54b559c44e3a28.zip
fixing ft_split_strict
-rw-r--r--Makefile4
-rw-r--r--ft_split_strict.c14
-rw-r--r--libft.h4
3 files changed, 11 insertions, 11 deletions
diff --git a/Makefile b/Makefile
index 814a2d6..1041c4b 100644
--- a/Makefile
+++ b/Makefile
@@ -6,7 +6,7 @@
# By: cacharle <marvin@42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2019/10/08 15:45:53 by cacharle #+# #+# #
-# Updated: 2020/02/04 04:08:01 by cacharle ### ########.fr #
+# Updated: 2020/02/04 20:22:40 by cacharle ### ########.fr #
# #
# **************************************************************************** #
@@ -28,7 +28,7 @@ SRC = ft_atoi.c ft_bzero.c ft_isalnum.c ft_isalpha.c ft_isascii.c ft_isdigit.c f
ft_strncat.c ft_strncmp.c ft_strncpy.c ft_strnequ.c ft_strnew.c ft_strnstr.c \
ft_strrchr.c ft_split.c ft_strstr.c ft_substr.c ft_strtrim.c ft_tolower.c \
ft_toupper.c ft_strlcpy.c ft_calloc.c ft_strcount.c ft_memswap.c ft_qsort.c \
- ft_abs.c ft_strtol.c ft_isspace.c
+ ft_abs.c ft_strtol.c ft_isspace.c ft_split_strict.c
OBJ = $(SRC:.c=.o)
INCLUDE = libft.h
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);
diff --git a/libft.h b/libft.h
index 49996c3..99c71db 100644
--- a/libft.h
+++ b/libft.h
@@ -6,7 +6,7 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/10/07 09:45:02 by cacharle #+# #+# */
-/* Updated: 2020/02/04 04:41:08 by cacharle ### ########.fr */
+/* Updated: 2020/02/04 20:23:20 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -15,6 +15,7 @@
# include <errno.h>
# include <string.h>
+# include <stdlib.h>
# define TRUE 1
# define FALSE 0
@@ -82,6 +83,7 @@ char *ft_substr(char const *s, unsigned int start, size_t len);
char *ft_strjoin(char const *s1, char const *s2);
char *ft_strtrim(char const *s1, char const *set);
char **ft_split(char const *s, char c);
+char **ft_split_strict(char const *s, char c);
char *ft_itoa(int n);
void ft_putendl(char *s);
void ft_putchar(char c);