-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_lstnew.c
53 lines (43 loc) · 1.88 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstnew.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mbrito-p <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/05/08 20:26:27 by mbrito-p #+# #+# */
/* Updated: 2023/05/08 20:26:27 by mbrito-p ### ########.fr */
/* */
/* ************************************************************************** */
// Allocates (with malloc(3)) and returns a new node.
// The member variable ’content’ is initialized with
// the value of the parameter ’content’. The variable
// ’next’ is initialized to NULL.
#include "libft.h"
t_list *ft_lstnew(void *content)
{
t_list *node;
node = (t_list *)malloc(sizeof(t_list));
if (!node)
return (NULL);
node->content = content;
node->next = NULL;
return (node);
}
// int main(void)
// {
// // Create a new node with an integer value
// int data = 42;
// t_list *node = ft_lstnew(&data);
// // Check if the node was created successfully
// if (node == NULL)
// {
// printf("Error: Failed to create new node\n");
// return EXIT_FAILURE;
// }
// // Print the contents of the new node
// printf("New node created with value %d\n", *(int *)node->content);
// // Free the memory allocated for the node
// free(node);
// return EXIT_SUCCESS;
// }