-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_lstlast.c
61 lines (51 loc) · 1.82 KB
/
ft_lstlast.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
54
55
56
57
58
59
60
61
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstlast.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ael-haib <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/02/07 00:51:03 by ael-haib #+# #+# */
/* Updated: 2024/02/14 22:34:31 by ael-haib ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
t_list *ft_lstlast(t_list *lst)
{
t_list *temp;
temp = lst;
if (temp == NULL)
return (NULL);
while (temp->next != NULL)
{
temp = temp->next;
}
return (temp);
}
/* int main()
{
t_list* head = NULL;
t_list* second = NULL;
t_list* third = NULL;
t_list* numberfor = NULL;
head = (t_list*)malloc(sizeof(t_list));
second = (t_list*)malloc(sizeof(t_list));
third = (t_list*)malloc(sizeof(t_list));
numberfor = (t_list*)malloc(sizeof(t_list));
head->content = (char *)"hohla";
second->content = (char *)"hi";
third->content = (char *)"how";
numberfor->content = (char *)"are you";
head->next = second;
second->next = third;
third->next = numberfor;
numberfor->next = NULL;
t_list *lastnode = ft_lstlast(head);
printf("Content of the last node: %s\n", (char *)lastnode->content);
printf("Content of the last node: %s\n", (char *)head->content);
free(head);
free(second);
free(third);
free(numberfor);
return (0);
} */