-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_read_map.c
69 lines (62 loc) · 1.59 KB
/
ft_read_map.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_read_map.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dhorvill <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/01/03 17:27:56 by dhorvill #+# #+# */
/* Updated: 2018/01/03 17:52:35 by dhorvill ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
#include <fcntl.h>
int ft_get_length(char *map)
{
int i;
int j;
int flag;
i = 0;
j = 0;
flag = 1;
while (map[i] && map[i] != '\n')
{
while (map[i] == ' ')
{
flag = 1;
i++;
}
while (map[i] && map[i] != ' ' && map[i] != '\n')
{
j = j + flag;
i++;
flag = 0;
}
}
return (j);
}
int ft_get_height(char *map)
{
int i;
char **pdt;
if ((pdt = ft_strsplit(map, '\n')) == 0)
return (0);
i = 0;
while (pdt[i])
i++;
return (i);
}
int main(int argc, char **argv)
{
int fd;
int ret;
int height;
int length;
char buf[5000];
fd = open(argv[1], O_RDONLY);
ret = read(fd, buf, 4999);
buf[ret] = '\0';
height = ft_get_height(buf);
length = ft_get_length(buf);
return (0);
}