-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinput_processor.c
52 lines (47 loc) · 1.49 KB
/
input_processor.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* input_processor.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mvalient <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/10 17:16:31 by mvalient #+# #+# */
/* Updated: 2022/12/21 12:27:40 by mvalient ### ########.fr */
/* */
/* ************************************************************************** */
#include "fdf.h"
static void ft_store_line(char **line, t_point **list)
{
static int y = 0;
int x;
x = 0;
while (line[x])
{
ft_add_point(&*list, x, y, ft_atoi(line[x]));
free(line[x]);
x++;
}
y++;
free(line);
}
t_point *ft_read_file(char *file)
{
t_point *point_list;
char *line;
int fd;
point_list = NULL;
line = NULL;
fd = open(file, O_RDONLY);
if (fd == -1)
return (NULL);
line = get_next_line(fd);
ft_store_line(ft_split(line, 32), &point_list);
while (line)
{
free(line);
line = get_next_line(fd);
if (line)
ft_store_line(ft_split(line, 32), &point_list);
}
return (point_list);
}