-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_tab.c
More file actions
95 lines (86 loc) · 1.82 KB
/
ft_tab.c
File metadata and controls
95 lines (86 loc) · 1.82 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* tab.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mtacnet <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/08/18 11:30:32 by mtacnet #+# #+# */
/* Updated: 2017/09/01 14:23:22 by mtacnet ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char **list_to_tab(t_elem **lst)
{
int i;
size_t j;
char **tab;
t_elem *head;
i = 0;
j = 0;
tab = NULL;
head = (*lst);
while ((*lst) != NULL)
{
j++;
(*lst) = (*lst)->next;
}
(*lst) = head;
if (!(tab = ft_memalloc(sizeof(*tab) * (j + 1))))
exit(EXIT_FAILURE);
while ((*lst) != NULL)
{
tab[i] = (*lst)->content;
(*lst) = (*lst)->next;
i++;
}
(*lst) = head;
return (tab);
}
void tab_to_list(t_elem **lst, char **tab)
{
int i;
i = 0;
while (tab[i] && tab[i][0] != '\0')
{
push_elem(lst, tab[i]);
i++;
}
}
void supp_elem_tab(char **tab, int value)
{
int i;
int j;
i = 0;
j = 0;
while (tab[i] && tab[i][0] != '\0')
i++;
if (value >= i)
return ;
else
{
while (j < i)
{
tab[j] = tab[j + 1];
j++;
}
}
return ;
}
void free_tab(char **tab)
{
int i;
i = 0;
while (tab[i])
{
if (tab[i] != NULL)
{
ft_strdel(&(tab[i]));
i++;
}
else
i++;
}
free(tab);
tab = NULL;
}