lstnew mis au point
This commit is contained in:
BIN
srcs/bonus/a.out
Executable file
BIN
srcs/bonus/a.out
Executable file
Binary file not shown.
13
srcs/bonus/ft_lstadd_back.c
Normal file
13
srcs/bonus/ft_lstadd_back.c
Normal file
@@ -0,0 +1,13 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstadd_back.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/11/20 15:14:22 by hulamy #+# #+# */
|
||||
/* Updated: 2019/11/20 15:14:35 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
13
srcs/bonus/ft_lstlast.c
Normal file
13
srcs/bonus/ft_lstlast.c
Normal file
@@ -0,0 +1,13 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstlast.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/11/20 15:13:43 by hulamy #+# #+# */
|
||||
/* Updated: 2019/11/20 15:13:58 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
@@ -6,29 +6,71 @@
|
||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2018/11/14 21:11:42 by hulamy #+# #+# */
|
||||
/* Updated: 2018/11/16 14:01:36 by hulamy ### ########.fr */
|
||||
/* Updated: 2019/11/20 16:39:29 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
/*
|
||||
** create a new list
|
||||
*/
|
||||
|
||||
/*
|
||||
** #include <libc.h>
|
||||
**
|
||||
** void *ft_memcpy(void *dst, const void *src, size_t n)
|
||||
** {
|
||||
** size_t i;
|
||||
** char *ptr;
|
||||
** char *ptr2;
|
||||
**
|
||||
** ptr = (char *)dst;
|
||||
** ptr2 = (char *)src;
|
||||
** i = -1;
|
||||
** while (++i < n)
|
||||
** ptr[i] = ptr2[i];
|
||||
** return (dst);
|
||||
** }
|
||||
**
|
||||
** 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("but not toto->content: %c\n",*(char*)(toto->content));
|
||||
** return (0);
|
||||
** }
|
||||
*/
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
t_list *ft_lstnew(void const *content, size_t content_size)
|
||||
t_list *ft_lstnew(void *content)
|
||||
{
|
||||
t_list *lst;
|
||||
|
||||
if (!(lst = (t_list *)malloc(sizeof(*lst))))
|
||||
return (NULL);
|
||||
if (!content)
|
||||
{
|
||||
lst->content = NULL;
|
||||
lst->content_size = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!(lst->content = malloc(content_size)))
|
||||
if (!(lst->content = malloc(sizeof(content))))
|
||||
return (NULL);
|
||||
ft_memcpy(lst->content, content, content_size);
|
||||
lst->content_size = content_size;
|
||||
ft_memcpy(lst->content, content, sizeof(content));
|
||||
}
|
||||
lst->next = NULL;
|
||||
return (lst);
|
||||
|
||||
14
srcs/bonus/ft_lstsize.c
Normal file
14
srcs/bonus/ft_lstsize.c
Normal file
@@ -0,0 +1,14 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstsize.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/11/20 15:12:55 by hulamy #+# #+# */
|
||||
/* Updated: 2019/11/20 15:13:11 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
Reference in New Issue
Block a user