correction de split pour retour valeur de null

This commit is contained in:
Hugo LAMY
2019-12-12 22:27:56 +01:00
parent 55b63ed47f
commit cf4203809f
3 changed files with 35 additions and 12 deletions

View File

@@ -6,7 +6,7 @@
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/11/25 13:55:51 by hulamy #+# #+# */
/* Updated: 2019/11/25 13:55:54 by hulamy ### ########.fr */
/* Updated: 2019/12/12 21:50:32 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
@@ -14,6 +14,27 @@
** locate character in string and return its position
*/
/*
** #include <libc.h>
**
** void *ft_memchr(const void *s, int c, size_t n);
**
** int main(void)
** {
** const char *str;
**
** char *pouet = "z";
** char *lolzer = (char *)&pouet[2];
** lolzer = "aaaaaaaaaa";
** str = ft_memchr(pouet, 'a', 50);
** if (!str)
** printf("NULL");
** else
** printf("%s\n", str);
** return (0);
** }
*/
#include "libft.h"
void *ft_memchr(const void *s, int c, size_t n)

View File

@@ -88,21 +88,25 @@ void *ft_free(char **array, int w)
return (NULL);
}
char **empty_s(char **empty)
{
if (!(empty = (char **)malloc(sizeof(char *) * 1)))
return (NULL);
empty[0] = NULL;
return (empty);
}
char **ft_split(char const *s, char c)
{
char **array;
int w;
int len;
w = 0;
// if (!s)
// {
// array = malloc(sizeof(char*));
// array[0] = 0;
// return (array);
// }
if (!s || !(array = (char **)malloc(sizeof(char *) * (count(s, c) + 1))))
if (!s)
return (empty_s(NULL));
if (!(array = (char **)malloc(sizeof(char *) * (count(s, c) + 1))))
return (NULL);
w = 0;
while (*s != '\0')
{
len = 0;

View File

@@ -20,9 +20,7 @@ void print_ft_split(char *str, char c)
printf("split : [%s] [%c] -> ", str, c);
tab = ft_split(str, c);
// while (*tab != NULL) sans verifier que tab est malloc
// printf("[%s]", *(tab++));
while (tab && *tab != NULL)
while (*tab != NULL)
printf("[%s]", *(tab++));
printf("\n");
}