parsing_input + create_square v1

Segfault
This commit is contained in:
Manzovince
2019-04-16 11:52:05 +02:00
parent e13cc70524
commit deef9d63b0

View File

@@ -6,7 +6,7 @@
/* By: vmanzoni <vmanzoni@student.42.fr> +#+ +:+ +#+ */ /* By: vmanzoni <vmanzoni@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2019/04/15 14:48:14 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 ** 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 = NULL;
char **square; int i;
int i; int k;
int j;
int k;
i = 0; i = 0;
while (input[i]) while (tetri[i])
{ {
j = 0; k = 0;
while (j < 4) *square = malloc((sizeof(char)*4) + 1);
while (k < 4)
{ {
k = 0; *square[k] = tetri[i];
while (k < 4) k++;
square[j][k++] = input[i++]; i++;
j++;
} }
printf("print:\n%s\n", *square); i++;
//add_to_list(square, &list); //printf("print:\n%s\n", *square);
while (input[i] == '\n') while (tetri[i] == '\n')
i++; i++;
} }
return (square);
} }
/*
void parse_input(char *input) void parse_input(char *input)
{ {
//static t_fillist *list = NULL; static t_fillist *list = NULL;
char square[19]; char tetri[20];
int i; int i;
int j; int j;
@@ -55,12 +53,13 @@ void parse_input(char *input)
{ {
j = 0; j = 0;
while (j < 19) while (j < 19)
square[j++] = input[i++]; tetri[j++] = input[i++];
square[19] = '\0'; tetri[19] = '\0';
printf("PRINT:\n%s\n", square); //printf("PRINT:\n%s\n", tetri);
//add_to_list(square, &list); if (check_tetri_errors(tetri))
print_error("Error: Tetrimino not valid.");
add_to_list(create_square(tetri), &list);
while (input[i] == '\n') while (input[i] == '\n')
i++; i++;
} }
} }
*/