correction lstnew erreur de malloc

This commit is contained in:
Hugo LAMY
2019-11-21 15:14:20 +01:00
parent 71e165f894
commit a3c44c565c
10 changed files with 337 additions and 54 deletions

View File

@@ -33,13 +33,13 @@
** t_list *toto;
**
** tresor = 'd';
** printf("tresor : %c\n",tresor);
** printf("tresor : %c\n",tresor);
** toto = ft_lstnew(&tresor);
** //toto->content was alocated as void* so it need cast
** printf("toto->content : %c\n",*(char*)(toto->content));
** printf("toto->content : %c\n",*(char*)(toto->content));
** tresor = 'D';
** printf("transform tresor : %c\n",tresor);
** printf("but not toto->content: %c\n",*(char*)(toto->content));
** printf("transform tresor : %c\n",tresor);
** printf("and also toto->content: %c\n",*(char*)(toto->content));
** return (0);
** }
*/
@@ -55,11 +55,7 @@ t_list *ft_lstnew(void *content)
if (!content)
lst->content = NULL;
else
{
if (!(lst->content = malloc(sizeof(content))))
return (NULL);
ft_memcpy(lst->content, content, sizeof(content));
}
lst->content = content;
lst->next = NULL;
return (lst);
}