From deef9d63b000ada568ae4951eace3d4024bd0938 Mon Sep 17 00:00:00 2001 From: Manzovince Date: Tue, 16 Apr 2019 11:52:05 +0200 Subject: [PATCH] parsing_input + create_square v1 Segfault --- parse_input.c | 49 ++++++++++++++++++++++++------------------------- 1 file changed, 24 insertions(+), 25 deletions(-) diff --git a/parse_input.c b/parse_input.c index a6f94d1..fcddb12 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/15 21:33:52 by vmanzoni ### ########.fr */ +/* Updated: 2019/04/16 11:50:45 by vmanzoni ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,37 +16,35 @@ ** Function that parse a file and put each tetrimino in a linked list */ -void parse_input(char *input) +char **create_square(char *tetri) { - //static t_fillist *list = NULL; - char **square; - int i; - int j; - int k; + char **square = NULL; + int i; + int k; i = 0; - while (input[i]) + while (tetri[i]) { - j = 0; - while (j < 4) + k = 0; + *square = malloc((sizeof(char)*4) + 1); + while (k < 4) { - k = 0; - while (k < 4) - square[j][k++] = input[i++]; - j++; + *square[k] = tetri[i]; + k++; + i++; } - printf("print:\n%s\n", *square); - //add_to_list(square, &list); - while (input[i] == '\n') + i++; + //printf("print:\n%s\n", *square); + while (tetri[i] == '\n') i++; } + return (square); } -/* void parse_input(char *input) { - //static t_fillist *list = NULL; - char square[19]; + static t_fillist *list = NULL; + char tetri[20]; int i; int j; @@ -55,12 +53,13 @@ void parse_input(char *input) { j = 0; while (j < 19) - square[j++] = input[i++]; - square[19] = '\0'; - printf("PRINT:\n%s\n", square); - //add_to_list(square, &list); + tetri[j++] = input[i++]; + tetri[19] = '\0'; + //printf("PRINT:\n%s\n", tetri); + if (check_tetri_errors(tetri)) + print_error("Error: Tetrimino not valid."); + add_to_list(create_square(tetri), &list); while (input[i] == '\n') i++; } } -*/