-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfilecheck.c
59 lines (52 loc) · 1 KB
/
filecheck.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
#include "fdf.h"
int ***ft_read_map(int fd)
{
char *line_content;
int gnl_ret;
int **map;
int **maptmp;
int lines;
line_content = NULL;
gnl_ret = 1;
lines = 0;
while (gnl_ret)
{
gnl_ret = get_next_line(fd, &line_content);
if (!(map = malloc(sizeof(int*) * lines + 1)))
ft_errorcode("malloc n'a pas pu malloquer");
if (gnl_ret)
{
maptmp = map;
free(map);
if (!(map = malloc(sizeof(int*) * lines + 1)))
ft_errorcode("malloc n'a pas pu malloquer");
ft_concat_map(&map, maptmp, line_content, lines);
lines++;
}
lines = gnl_ret ? lines + 1 : line;
}
}
void ft_concat_map(int ***map, int **maptmp, char *line_content, int lines)
{
int *new_line;
if (!(new_line = malloc(sizeof(int) * ft_mapwidth(line_content))))
ft_errorcode("malloc n'a pas pu malloquer");
}
int ft_mapwidth(char *line)
{
int i;
int width;
i = 0;
width = 0;
while (line[i])
{
if (line[i] != '\t')
{
while (line[i] && line[i] != '\t')
i++;
width++;
}
i++;
}
return (width);
}