From 781121e3d4b1c3c17878ac386be5aafdaa04bbf4 Mon Sep 17 00:00:00 2001 From: Hugo LAMY Date: Sun, 14 Apr 2019 23:04:30 +0200 Subject: [PATCH] les mallocs pour remplir le result sont bons --- includes/.fillit.h.swp | Bin 12288 -> 12288 bytes includes/fillit.h | 3 ++- srcs/.add_to_list.c.swp | Bin 12288 -> 12288 bytes srcs/add_to_list.c | 37 ++++++++++++++++++++++++++++++++++++- 4 files changed, 38 insertions(+), 2 deletions(-) diff --git a/includes/.fillit.h.swp b/includes/.fillit.h.swp index 9dd6db16a5734e01888588101f765cab98dcc481..e736c25bb705736c65d1b2cdab6d5dd9884dba86 100644 GIT binary patch delta 127 zcmZojXh;xCG6?hZRWR2xVE_UF28O@WHpfg_wNdOcGizx{ny$s>cg#vWjE0*91wQlh zN^mkT`~YH*Lc_^|3fslBxfmFPfS3V@|3hWJb8cp25$9x9R#u+Ou4TiLSd^N$*+Pqh TnZwA)%E-jZ$a1rX?hYmZ0;V1% delta 111 zcmZojXh;xCG6?hZRWR2xVE_UF28L3X%`v-LH;P?mo|wS8`5m(o52L|mL4nWwyxN=$ z4D4JGRR)s<6}Ag00(tyE%m>6E88)uXj4ZmGlYeO1Y +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/03/01 13:34:46 by vmanzoni #+# #+# */ -/* Updated: 2019/04/14 16:32:21 by hulamy ### ########.fr */ +/* Updated: 2019/04/14 22:24:29 by hulamy ### ########.fr */ /* */ /* ************************************************************************** */ @@ -42,6 +42,7 @@ typedef struct s_fillist char **tetraminos; int position[2]; int size[2]; + int area; struct s_fillist *next; } t_fillist; diff --git a/srcs/.add_to_list.c.swp b/srcs/.add_to_list.c.swp index 1877c208aeb9e4325976a1177cc23ca44db7df22..7f05fbb2001057583c93fee66b6aed9c40ceda61 100644 GIT binary patch delta 1144 zcmZY7Ur19?90%~9OS2n<3L!yIM@e_@=EkOy;99R0sPv)~y4>8(+!@zv-rePDj_sk> z1Q|$?G^3Y@2y7tr&{Gf5TTt|z(I0#*@WF@Zd+zS$vO7N9bI$$k_dCCHZz)=ecFzT- zu8gx0|1ja|Bs#lUojJL+)xF=*VpO|2e|MaC<04vXtvxl$U93`kp%6WX4OoQ|EQ0|H zz+nPLVDA{wclZn+VHH*&3fEx@#=#4J+7S=m;4AFFGk6LWSciMYEt;a82U4?^-3i4N7cOP#llA_!+g<&Pt-oDI?(L2C&k+FOiEpC~y1z{{^ zrbR>xk+Pf;I%lfaE7%1mCL`|f>0m@7MX)gQ1rc@l&sa|iU7t01A{*z4*@LudW+@vp z=lB521qaw|$PMB?C~MVs6f=2@^(C6NC0Arbt&aUX+`OAWgn63h!APiDQQKNvB2<2) z%@s{eR?f|i`HFkUQ{b8>lBuFIndga`w}!s*KuIS}opV51>pulH-UOzSlhH2~&S?|e$ z3iIoaaxyR+2I5^nyb*|30P%bvo(IHJfVc~Y8-ch2h~0r$6o|ibFfiN%;sroF4~XXi zaV-#6192u0X8>_55NiXmED-+&+V~EL-vIGzAU+4gXMlJgJA*L8ZXja?5HAJd89+RZ qeKR9V2;1g~DqM`4Yt>j7CwHpHY|?UMW;e1jG`BJ^+3caag9!i +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/04/14 15:20:53 by hulamy #+# #+# */ -/* Updated: 2019/04/14 22:17:04 by hulamy ### ########.fr */ +/* Updated: 2019/04/14 23:03:46 by hulamy ### ########.fr */ /* */ /* ************************************************************************** */ @@ -36,12 +36,40 @@ void find_start_and_end(char **square, int *x1, int *x2, int *y1, int *y2) i--; } +char **fill_reduced_tetraminos(char **square, int x1, int y1, int x2, int y2) +{ + char **result; + int height; + int length; + int i; + int j; + + i = 0; + height = x2 - x1 + 1; + length = y2 - y1 + 1; + if (!(result = (char**)malloc(sizeof(*result) * (height + 1)))) + return (NULL); + while (i < 4) + { + if (!(result[i] = (char*)malloc(sizeof(**result) * (length + 1)))) + return (NULL); + result[i][length] = '\0'; + i++; + } + i = -1; + while (++i < height && !(j = 0)) + while (j < length && (result[i][j] = '.')) + j++; + return (result); +} + void reduce_tetraminos(char **square, t_fillist *list) { int x1; int x2; int y1; int y2; + int i; x1 = -1; y1 = -1; @@ -52,6 +80,13 @@ void reduce_tetraminos(char **square, t_fillist *list) list->size[0] = y2 - y1 + 1; list->size[1] = x2 - x1 + 1; printf("size [%d,%d]\n", list->size[0], list->size[1]); + list->area = list->size[0] * list->size[1]; + printf("area %d\n", list->area); + list->tetraminos = fill_reduced_tetraminos(square, x1, y1, x2, y2); + i = -1; + while (++i < list->size[1]) + printf("%s\n", list->tetraminos[i]); + } int add_to_list(char **square)