58 lines
1.7 KiB
Plaintext
58 lines
1.7 KiB
Plaintext
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* ft_lstnew.c :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2019/11/25 14:16:20 by hulamy #+# #+# */
|
|
/* Updated: 2022/03/23 20:24:40 by simplonco ### ########.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
/*
|
|
** create a new list
|
|
*/
|
|
|
|
/*
|
|
** #include <libc.h>
|
|
**
|
|
** typedef struct s_list
|
|
** {
|
|
** void *content;
|
|
** struct s_list *next;
|
|
** } t_list;
|
|
**
|
|
** t_list *ft_lstnew(void *content);
|
|
**
|
|
** int main(void)
|
|
** {
|
|
** char tresor;
|
|
** t_list *toto;
|
|
**
|
|
** tresor = 'd';
|
|
** 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));
|
|
** tresor = 'D';
|
|
** printf("transform tresor : %c\n",tresor);
|
|
** printf("and also toto->content: %c\n",*(char*)(toto->content));
|
|
** return (0);
|
|
** }
|
|
*/
|
|
|
|
#include "libft.h"
|
|
|
|
t_list *ft_lstnew(void *content)
|
|
{
|
|
t_list *lst;
|
|
|
|
lst = (t_list *)malloc(sizeof(*lst));
|
|
if (!lst)
|
|
return (NULL);
|
|
lst->content = content;
|
|
lst->next = NULL;
|
|
return (lst);
|
|
}
|