fix pbm with get_next_line

This commit is contained in:
asus
2024-01-19 18:52:58 +01:00
parent 78d6e35c7f
commit 60b4a82489
10 changed files with 127 additions and 118 deletions

View File

@@ -102,7 +102,7 @@ int check_elements(t_game *game, char *file)
return (-1);
while (count < TOTAL_ELEMENTS)
{
get_next_line(fd, &line);
ft_gnl(fd, &line);
mb_add(line);
if (line && *line != '\n' && !check_element(game, line))
count++;

View File

@@ -15,15 +15,19 @@
static int size_map(t_map *map, int fd)
{
char *line;
int ret;
get_next_line(fd, &line);
ret = ft_gnl(fd, &line);
mb_add(line);
while (line)
while (ret > 0)
{
if ((*line == '\n' || *line == '\0') && map->size_x)
if (ret != 0 && map->size_x)
{
mb_free(line);
return (EXIT_FAILURE);
if (*line == '\n' || *line == '\0')
{
mb_free(line);
return (EXIT_FAILURE);
}
}
else if (*line != '\n' && (int)ft_strlen(line) > map->size_x)
{
@@ -35,7 +39,7 @@ static int size_map(t_map *map, int fd)
map->size_y++;
mb_free(line);
line = NULL;
get_next_line(fd, &line);
ret = ft_gnl(fd, &line);
mb_add(line);
}
return (EXIT_SUCCESS);
@@ -52,7 +56,7 @@ static int find_map(t_map *map, char *file)
return (-1);
while (count < TOTAL_ELEMENTS + 1)
{
get_next_line(fd, &map->tmp_str);
ft_gnl(fd, &map->tmp_str);
mb_add(map->tmp_str);
if (!map->tmp_str)
{
@@ -100,7 +104,7 @@ static void fill_map(t_map *map, int fd)
{
if (i > 0)
{
ret = get_next_line(fd, &map->tmp_str);
ret = ft_gnl(fd, &map->tmp_str);
mb_add(map->tmp_str);
}
map->content[i] = (char *)mb_alloc((map->size_x + 1) * sizeof(char));
@@ -110,7 +114,7 @@ static void fill_map(t_map *map, int fd)
map->content[i] = NULL;
while (ret)
{
ret = get_next_line(fd, &map->tmp_str);
ret = ft_gnl(fd, &map->tmp_str);
if (ret)
mb_add(map->tmp_str);
}