-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_next_line_utils.c
92 lines (81 loc) · 1.95 KB
/
get_next_line_utils.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
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* get_next_line_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mcatal-d <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/11/21 13:01:39 by mcatal-d #+# #+# */
/* Updated: 2022/11/21 14:45:34 by mcatal-d ### ########.fr */
/* */
/* ************************************************************************** */
#include "get_next_line.h"
int nouvelle_ligne(t_list *reserve)
{
int i;
t_list *current;
if (reserve == NULL)
return (0);
current = dernier_maillon(reserve);
i = 0;
while (current -> content[i])
{
if (current -> content[i] == '\n')
return (1);
i++;
}
return (0);
}
t_list *dernier_maillon(t_list *reserve)
{
t_list *current;
current = reserve;
while (current && current -> next)
current = current -> next;
return (current);
}
void malloc_ligne(char **line, t_list *reserve)
{
int i;
int len;
len = 0;
while (reserve)
{
i = 0;
while (reserve -> content[i])
{
if (reserve -> content[i] == '\n')
{
len++;
break ;
}
len++;
i++;
}
reserve = reserve -> next;
}
*line = malloc(sizeof(char) * (len + 1));
if (*line == NULL)
return ;
}
void free_reserve(t_list *reserve)
{
t_list *current;
t_list *next;
current = reserve;
while (current)
{
free(current -> content);
next = current -> next;
free(current);
current = next;
}
}
int ft_strlen(const char *str)
{
int len;
len = 0;
while (*(str++))
len++;
return (len);
}