-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_ft_lstlast.c
54 lines (50 loc) · 1.67 KB
/
test_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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* test_ft_lstlast.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jliew <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/07/06 19:46:33 by jliew #+# #+# */
/* Updated: 2020/07/09 23:20:16 by jliew ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdio.h>
#include <string.h>
#include "libft.h"
void print_list(t_list *list)
{
while (list)
{
printf("[%s]", list->content);
printf("%s", ((list->next) ? " -> " : "\n"));
list = list->next;
}
}
int main(int argc, char **argv)
{
int i;
t_list *list;
t_list *last;
if (argc == 1)
{
printf("--------------------------------\n");
printf(" t_list ft_lstlast(t_list *lst)\n");
printf("--------------------------------\n");
printf("usage [manual]:\n");
printf("1. a --list <. . .>\n");
return (42);
}
else if (!strcmp(argv[1], "--list"))
{
list = NULL;
i = 2;
while (i < argc)
ft_lstadd_back(&list, ft_lstnew(strdup(argv[i++])));
print_list(list);
last = ft_lstlast(list);
if (last)
printf("last content: [%s]\n", last->content);
ft_lstclear(&list, free);
}
}