-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_lstnew.c
38 lines (32 loc) · 1.59 KB
/
ft_lstnew.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstnew.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: amait-ou <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/05 06:25:50 by amait-ou #+# #+# */
/* Updated: 2023/01/24 00:07:19 by amait-ou ### ########.fr */
/* */
/* ************************************************************************** */
/*
the only two things we know before creating a node are:
- the content of the node is void pointer (this will allow us to store
any kind of data)
- the next of this node is a pointer which points to NULL
first of all, we have to allocate a memory for our new node using the malloc
function, and if allocation fails, "NULL" will be returned.
after the allocation we assign the parameter of the function to the new
node's content meanwhile its next will be "NULL" (mostly it is the last node)
*/
#include "./superlib.h"
t_list *ft_lstnew(void *content)
{
t_list *node;
node = (t_list *)malloc(sizeof(t_list));
if (!node)
return ((void *)0);
node->content = content;
node->next = (void *)0;
return (node);
}