Create map with copy

This commit is contained in:
Andrei Pago 2023-04-05 17:18:28 +02:00
parent cf95458e17
commit ccf063f3aa
3 changed files with 16 additions and 41 deletions

View File

@ -6,7 +6,7 @@
/* By: apago <apago@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/04/04 18:22:11 by apago #+# #+# */
/* Updated: 2023/04/05 09:31:04 by tischmid ### ########.fr */
/* Updated: 2023/04/05 17:17:26 by apago ### ########.fr */
/* */
/* ************************************************************************** */
@ -41,5 +41,6 @@ int read_char(char *str, char *dst);
int printable(char c);
size_t count_first_line(char *line);
int read_fname(char *name, t_map *map);
void copy_bytes(char *dst, char *src, size_t bytes);
#endif

View File

@ -3,57 +3,24 @@
/* ::: :::::::: */
/* main.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tischmid <marvin@42.fr> +#+ +:+ +#+ */
/* By: apago <apago@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/04/04 21:50:50 by tischmid #+# #+# */
/* Updated: 2023/04/05 11:04:31 by tischmid ### ########.fr */
/* Updated: 2023/04/05 17:14:36 by apago ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdio.h>
#include "solution.h"
#include "printing.h"
#include "ft_string.h"
void debug_set_map(t_map *map)
{
char *str;
str = \
"........................................" \
"...................X...................." \
".........................X..........X..." \
"..............X........................." \
".........X...........................X.." \
"............X..X........................" \
"..................................X....." \
"....................................X..." \
"........................................" \
"X.X..........................X.........." \
"....X.................................X." \
"..........X............................." \
".............................X.........." \
"....................X......X............" \
"............................X...X......X" \
".......X........X....X....X..XX........." \
"................X........X............X." \
"................X......X................" \
"....X................X.......X.........." \
"........................................";
map->data = malloc(sizeof(char) * (ft_strlen(str) + 1));
ft_strcpy(map->data, str);
}
#include "printing.h"
#include "solution.h"
#include <stdio.h>
int main(void)
{
t_map map;
if (!read_fname("./assets/map20x40.map", &map))
if (!read_fname("./assets/subject.map", &map))
return (ft_err("map error\n", 1));
free(map.data);
debug_set_map(&map);
map.copy = malloc(sizeof(char) * (ft_strlen(map.data) + 1));
ft_strcpy(map.copy, map.data);
solve(&map);
print_map(&map, 0);
free(map.data);

View File

@ -6,7 +6,7 @@
/* By: apago <apago@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/04/04 16:19:27 by apago #+# #+# */
/* Updated: 2023/04/05 16:42:50 by apago ### ########.fr */
/* Updated: 2023/04/05 17:16:41 by apago ### ########.fr */
/* */
/* ************************************************************************** */
@ -103,6 +103,13 @@ int parse_input(char *str, t_map *map)
map->data = parse_data(&str[offset], &map->meta);
if (!map->data)
return (0);
map->copy = malloc(sizeof(char) * (map->meta.width * map->meta.height));
if (!map->copy)
{
free(map->data);
return (0);
}
copy_bytes(map->copy, map->data, map->meta.width * map->meta.height);
return (1);
}