repare parseur avec probleme malloc

This commit is contained in:
Hugo LAMY
2019-04-16 15:32:57 +02:00
parent 98dd7b90c5
commit 6c4577fafd
10 changed files with 53 additions and 41 deletions

Binary file not shown.

View File

@@ -6,14 +6,14 @@
# By: vmanzoni <vmanzoni@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# 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)

View File

@@ -6,7 +6,7 @@
/* By: hulamy <hulamy@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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);
**}
*/

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
main.o

Binary file not shown.

View File

@@ -6,7 +6,7 @@
/* By: vmanzoni <vmanzoni@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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;
}
}

Binary file not shown.