Create map with copy
This commit is contained in:
parent
cf95458e17
commit
ccf063f3aa
|
@ -6,7 +6,7 @@
|
||||||
/* By: apago <apago@student.42.fr> +#+ +:+ +#+ */
|
/* By: apago <apago@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/04/04 18:22:11 by apago #+# #+# */
|
/* 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);
|
int printable(char c);
|
||||||
size_t count_first_line(char *line);
|
size_t count_first_line(char *line);
|
||||||
int read_fname(char *name, t_map *map);
|
int read_fname(char *name, t_map *map);
|
||||||
|
void copy_bytes(char *dst, char *src, size_t bytes);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
45
srcs/main.c
45
srcs/main.c
|
@ -3,57 +3,24 @@
|
||||||
/* ::: :::::::: */
|
/* ::: :::::::: */
|
||||||
/* main.c :+: :+: :+: */
|
/* main.c :+: :+: :+: */
|
||||||
/* +:+ +:+ +:+ */
|
/* +:+ +:+ +:+ */
|
||||||
/* By: tischmid <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: apago <apago@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/04/04 21:50:50 by tischmid #+# #+# */
|
/* 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"
|
#include "ft_string.h"
|
||||||
|
#include "printing.h"
|
||||||
void debug_set_map(t_map *map)
|
#include "solution.h"
|
||||||
{
|
#include <stdio.h>
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
t_map map;
|
t_map map;
|
||||||
|
|
||||||
if (!read_fname("./assets/map20x40.map", &map))
|
if (!read_fname("./assets/subject.map", &map))
|
||||||
return (ft_err("map error\n", 1));
|
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);
|
solve(&map);
|
||||||
print_map(&map, 0);
|
print_map(&map, 0);
|
||||||
free(map.data);
|
free(map.data);
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: apago <apago@student.42.fr> +#+ +:+ +#+ */
|
/* By: apago <apago@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/04/04 16:19:27 by apago #+# #+# */
|
/* 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);
|
map->data = parse_data(&str[offset], &map->meta);
|
||||||
if (!map->data)
|
if (!map->data)
|
||||||
return (0);
|
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);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue