ft_lstnew: initial implementation
This commit is contained in:
parent
1126640edc
commit
8777bfc3c3
3 changed files with 50 additions and 2 deletions
7
Makefile
7
Makefile
|
|
@ -6,7 +6,7 @@
|
|||
# By: kcolin <marvin@42.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2024/10/14 13:43:59 by kcolin #+# #+# #
|
||||
# Updated: 2024/10/21 11:13:58 by kcolin ### ########.fr #
|
||||
# Updated: 2024/10/21 11:19:20 by kcolin ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
|
|
@ -47,6 +47,8 @@ SOURCES = ft_isalpha.c \
|
|||
ft_putendl_fd.c \
|
||||
ft_putnbr_fd.c
|
||||
OBJECTS = $(SOURCES:.c=.o)
|
||||
BONUS_SOURCES = ft_lstnew_bonus.c
|
||||
BONUS_OBJECTS = $(BONUS_SOURCES:.c=.o)
|
||||
|
||||
.PHONY: all
|
||||
all: $(NAME)
|
||||
|
|
@ -54,6 +56,9 @@ all: $(NAME)
|
|||
$(NAME): $(OBJECTS)
|
||||
ar rcs libft.a $(OBJECTS)
|
||||
|
||||
bonus: $(OBJECTS) $(BONUS_OBJECTS)
|
||||
ar rcs libft.a $(OBJECTS) $(BONUS_OBJECTS)
|
||||
|
||||
.PHONY: fclean
|
||||
fclean: clean
|
||||
rm -f libft.a
|
||||
|
|
|
|||
41
ft_lstnew_bonus.c
Normal file
41
ft_lstnew_bonus.c
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstnew_bonus.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: kcolin <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/10/21 11:19:42 by kcolin #+# #+# */
|
||||
/* Updated: 2024/10/21 11:25:46 by kcolin ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
t_list *ft_lstnew(void *content)
|
||||
{
|
||||
t_list *out;
|
||||
|
||||
out = malloc(sizeof(t_list));
|
||||
if (out == NULL)
|
||||
return (NULL);
|
||||
out->content = content;
|
||||
out->next = NULL;
|
||||
return (out);
|
||||
}
|
||||
|
||||
/*
|
||||
#include <stdio.h>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
t_list *list;
|
||||
|
||||
list = ft_lstnew("Hello There!");
|
||||
printf("content:\t%s\n", (char *)list->content);
|
||||
printf("next:\t%p\n", list->next);
|
||||
free(list);
|
||||
return (0);
|
||||
}
|
||||
*/
|
||||
4
libft.h
4
libft.h
|
|
@ -6,7 +6,7 @@
|
|||
/* By: kcolin <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/10/15 10:11:54 by kcolin #+# #+# */
|
||||
/* Updated: 2024/10/21 11:10:52 by kcolin ### ########.fr */
|
||||
/* Updated: 2024/10/21 11:11:02 by kcolin ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -69,4 +69,6 @@ typedef struct s_list
|
|||
struct s_list *next;
|
||||
} t_list;
|
||||
|
||||
t_list *ft_lstnew(void *content);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue