diff --git a/.add_to_list.c.swp b/.add_to_list.c.swo similarity index 98% rename from .add_to_list.c.swp rename to .add_to_list.c.swo index 20b25b5..9f660c7 100644 Binary files a/.add_to_list.c.swp and b/.add_to_list.c.swo differ diff --git a/.parse_input.c.swp b/.parse_input.c.swp index 9396aa2..811fc0b 100644 Binary files a/.parse_input.c.swp and b/.parse_input.c.swp differ diff --git a/Makefile b/Makefile index e6b9426..a11ddf9 100644 --- a/Makefile +++ b/Makefile @@ -6,14 +6,14 @@ # By: vmanzoni +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2019/03/01 13:24:35 by vmanzoni #+# #+# # -# Updated: 2019/04/15 20:17:47 by vmanzoni ### ########.fr # +# Updated: 2019/04/16 14:05:39 by hulamy ### ########.fr # # # # **************************************************************************** # NAME = fillit -OBJ_DIR = objs/ -HEADER = includes/ +OBJ_DIR = ./ +HEADER = ./ SRCS = *.c OBJS = $(SRCS:.c=.o) diff --git a/add_to_list.c b/add_to_list.c index 4fda9a6..0eb22ac 100644 --- a/add_to_list.c +++ b/add_to_list.c @@ -6,7 +6,7 @@ /* By: hulamy +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/04/14 15:20:53 by hulamy #+# #+# */ -/* Updated: 2019/04/15 20:49:33 by vmanzoni ### ########.fr */ +/* Updated: 2019/04/16 15:32:14 by hulamy ### ########.fr */ /* */ /* ************************************************************************** */ @@ -29,7 +29,7 @@ char **fill_tetraminos(char **square, int *tab) i = 0; height = tab[2] - tab[0] + 1; length = tab[3] - tab[1] + 1; - if (!(result = (char**)malloc(sizeof(*result) * (height)))) + if (!(result = (char**)malloc(sizeof(*result) * (height + 1)))) return (NULL); while (i < height) { @@ -128,25 +128,25 @@ int add_to_list(char **square, t_fillist **list) } /* -int main(int ac, char **av) -{ - static t_fillist *list = NULL; // avant d'appeller add_to_list il faut declarer un pointeur static vers la structure - int i; - - if (ac > 1) - { - add_to_list(++av, &list); // l'appel de la fonction se fait avec un carre valide de 4*4 et l'adresse du pointeur vers la liste - if (ac == 9) - add_to_list(av += 4, &list); - while (list && (i = -1)) - { - while (++i < list->size[1]) - printf("%s\n", list->tetraminos[i]); - printf("\n"); - list = list->next; - } - } - - return (0); -} +**int main(int ac, char **av) +**{ +** static t_fillist *list = NULL; // avant d'appeller add_to_list il faut declarer un pointeur static vers la structure +** int i; +** +** if (ac > 1) +** { +** add_to_list(++av, &list); // l'appel de la fonction se fait avec un carre valide de 4*4 et l'adresse du pointeur vers la liste +** if (ac == 9) +** add_to_list(av += 4, &list); +** while (list && (i = -1)) +** { +** while (++i < list->size[1]) +** printf("%s\n", list->tetraminos[i]); +** printf("\n"); +** list = list->next; +** } +** } +** +** return (0); +**} */ diff --git a/add_to_list.o b/add_to_list.o deleted file mode 100644 index 22acb67..0000000 Binary files a/add_to_list.o and /dev/null differ diff --git a/get_smallest_square.o b/get_smallest_square.o deleted file mode 100644 index ea38629..0000000 Binary files a/get_smallest_square.o and /dev/null differ diff --git a/handle_errors.o b/handle_errors.o deleted file mode 100644 index 1c43c0b..0000000 Binary files a/handle_errors.o and /dev/null differ diff --git a/main.o b/main.o deleted file mode 100644 index 307244d..0000000 Binary files a/main.o and /dev/null differ diff --git a/parse_input.c b/parse_input.c index fcddb12..122a202 100644 --- a/parse_input.c +++ b/parse_input.c @@ -6,7 +6,7 @@ /* By: vmanzoni +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/04/15 14:48:14 by vmanzoni #+# #+# */ -/* Updated: 2019/04/16 11:50:45 by vmanzoni ### ########.fr */ +/* Updated: 2019/04/16 15:28:11 by hulamy ### ########.fr */ /* */ /* ************************************************************************** */ @@ -18,25 +18,24 @@ char **create_square(char *tetri) { - char **square = NULL; + char **square; int i; int k; i = 0; - while (tetri[i]) + if (!(square = (char**)malloc(sizeof(*square) * 4))) + return (NULL); + while (*tetri && (k = -1)) { - k = 0; - *square = malloc((sizeof(char)*4) + 1); - while (k < 4) - { - *square[k] = tetri[i]; - k++; - i++; - } + if (!(square[i] = (char*)malloc(sizeof(**square) * (4 + 1)))) + return (NULL); + square[i][4] = '\0'; + while (++k < 4) + square[i][k] = *(tetri++); + while (*tetri == '\n') + tetri++; + // printf("%s\n", square[i]); i++; - //printf("print:\n%s\n", *square); - while (tetri[i] == '\n') - i++; } return (square); } @@ -47,6 +46,7 @@ void parse_input(char *input) char tetri[20]; int i; int j; + char **test; i = 0; while (input[i]) @@ -58,8 +58,20 @@ void parse_input(char *input) //printf("PRINT:\n%s\n", tetri); if (check_tetri_errors(tetri)) print_error("Error: Tetrimino not valid."); - add_to_list(create_square(tetri), &list); + test = create_square(tetri); + add_to_list(test, &list); while (input[i] == '\n') i++; } + /* + ** ce qui suit sert juste a afficher le contenu de tous les tetraminos de la liste chainee + ** pour debug, a effacer au rendu + */ + while (list && (i = -1)) + { + while (++i < list->size[1]) + printf("%s\n", list->tetraminos[i]); + printf("\n"); + list = list->next; + } } diff --git a/print_fillit.o b/print_fillit.o deleted file mode 100644 index 8234f4b..0000000 Binary files a/print_fillit.o and /dev/null differ