reorganisation pour rendu et free dans split
This commit is contained in:
66
Makefile
66
Makefile
@@ -64,39 +64,39 @@ SRCB = ft_lstnew.c \
|
|||||||
ft_lstdelone.c \
|
ft_lstdelone.c \
|
||||||
ft_lstclear.c \
|
ft_lstclear.c \
|
||||||
ft_lstiter.c \
|
ft_lstiter.c \
|
||||||
ft_lstmap.c \
|
ft_lstmap.c
|
||||||
\
|
# \
|
||||||
ft_strcat.c \
|
# ft_strcat.c \
|
||||||
ft_strcmp.c \
|
# ft_strcmp.c \
|
||||||
ft_strcpy.c \
|
# ft_strcpy.c \
|
||||||
ft_strncat.c \
|
# ft_strncat.c \
|
||||||
ft_strncpy.c \
|
# ft_strncpy.c \
|
||||||
ft_strstr.c \
|
# ft_strstr.c \
|
||||||
ft_strjoinfree.c \
|
# ft_strjoinfree.c \
|
||||||
ft_strclr.c \
|
# ft_strclr.c \
|
||||||
ft_strdel.c \
|
# ft_strdel.c \
|
||||||
ft_strequ.c \
|
# ft_strequ.c \
|
||||||
ft_striter.c \
|
# ft_striter.c \
|
||||||
ft_striteri.c \
|
# ft_striteri.c \
|
||||||
ft_strmap.c \
|
# ft_strmap.c \
|
||||||
ft_strnequ.c \
|
# ft_strnequ.c \
|
||||||
ft_strnew.c \
|
# ft_strnew.c \
|
||||||
ft_memalloc.c \
|
# ft_memalloc.c \
|
||||||
ft_memdel.c \
|
# ft_memdel.c \
|
||||||
ft_putchar.c \
|
# ft_putchar.c \
|
||||||
ft_putendl.c \
|
# ft_putendl.c \
|
||||||
ft_putnbr.c \
|
# ft_putnbr.c \
|
||||||
ft_putnbrendl.c \
|
# ft_putnbrendl.c \
|
||||||
ft_putnbrendl_fd.c \
|
# ft_putnbrendl_fd.c \
|
||||||
ft_putnbrbase.c \
|
# ft_putnbrbase.c \
|
||||||
ft_putstr.c \
|
# ft_putstr.c \
|
||||||
ft_any.c \
|
# ft_any.c \
|
||||||
ft_atoibase.c \
|
# ft_atoibase.c \
|
||||||
ft_convertbase.c \
|
# ft_convertbase.c \
|
||||||
ft_foreach.c \
|
# ft_foreach.c \
|
||||||
ft_issort.c \
|
# ft_issort.c \
|
||||||
ft_arraymap.c \
|
# ft_arraymap.c \
|
||||||
ft_strmultisplit.c
|
# ft_strmultisplit.c
|
||||||
|
|
||||||
OBJB = $(SRCB:%.c=$(ODIR)/%.o)
|
OBJB = $(SRCB:%.c=$(ODIR)/%.o)
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2019/11/25 14:00:13 by hulamy #+# #+# */
|
/* Created: 2019/11/25 14:00:13 by hulamy #+# #+# */
|
||||||
/* Updated: 2019/12/01 16:01:20 by hulamy ### ########.fr */
|
/* Updated: 2019/12/02 17:48:50 by hulamy ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -92,6 +92,13 @@ static int ft_count_word(char const *s, char c)
|
|||||||
return (words);
|
return (words);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void *ft_free(char **array)
|
||||||
|
{
|
||||||
|
while (array)
|
||||||
|
free(array++);
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
|
|
||||||
char **ft_split(char const *s, char c)
|
char **ft_split(char const *s, char c)
|
||||||
{
|
{
|
||||||
char **array;
|
char **array;
|
||||||
@@ -99,12 +106,12 @@ char **ft_split(char const *s, char c)
|
|||||||
int j;
|
int j;
|
||||||
int len;
|
int len;
|
||||||
|
|
||||||
|
i = ft_count_word(s, c);
|
||||||
|
if (!s || !c || !(array = malloc(sizeof(char *) * (i + 1))))
|
||||||
|
return (NULL);
|
||||||
|
array[i] = 0;
|
||||||
i = -1;
|
i = -1;
|
||||||
j = 0;
|
j = 0;
|
||||||
if (!s || !c)
|
|
||||||
return (NULL);
|
|
||||||
if (!(array = (char **)malloc(sizeof(char *) * (ft_count_word(s, c) + 1))))
|
|
||||||
return (NULL);
|
|
||||||
while (s[++i])
|
while (s[++i])
|
||||||
{
|
{
|
||||||
if (s[i] != c)
|
if (s[i] != c)
|
||||||
@@ -112,10 +119,10 @@ char **ft_split(char const *s, char c)
|
|||||||
len = 0;
|
len = 0;
|
||||||
while (s[i + len] && s[i + len] != c)
|
while (s[i + len] && s[i + len] != c)
|
||||||
len++;
|
len++;
|
||||||
array[j++] = ft_substr(s, i, len);
|
if (!(array[j++] = ft_substr(s, i, len)))
|
||||||
|
return (ft_free(array));
|
||||||
i = i + len - 1;
|
i = i + len - 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
array[j] = 0;
|
|
||||||
return (array);
|
return (array);
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user