From 6c6bd307f8876ef7861a59ac0d860cfac414ced2 Mon Sep 17 00:00:00 2001 From: Naej Date: Sat, 24 Dec 2016 16:07:50 +0100 Subject: [PATCH] =?UTF-8?q?en=20fait=20il=20n'y=20avait=20pas=20de=20bug?= =?UTF-8?q?=20sur=20le=20point=20abord=C3=A9=20ds=20le=20commit=20preceden?= =?UTF-8?q?t,=20commence=20free=20matrix,=20necessite=20une=20mise=20au=20?= =?UTF-8?q?pt=20avec=20sli?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LibAutomaton/CellElement.c | 3 ++- LibAutomaton/CellElement.h | 2 -- LibAutomaton/matrix.c | 20 ++++++++++++++++++-- LibAutomaton/matrix.h | 2 ++ main.c | 12 +++++++++--- 5 files changed, 31 insertions(+), 8 deletions(-) diff --git a/LibAutomaton/CellElement.c b/LibAutomaton/CellElement.c index 165425f..96fc5c8 100644 --- a/LibAutomaton/CellElement.c +++ b/LibAutomaton/CellElement.c @@ -16,7 +16,6 @@ cellElement * CreateCellElem(){ printf("---Created cellElement---\n"); - elem->value = true; elem->nextCol = NULL; elem->nextRow = NULL; @@ -132,6 +131,8 @@ void FreeCellElement(cellElement* element) { if (element != NULL){ free(element); + }else{ + printf("Cant free NULL"); } element = NULL; } diff --git a/LibAutomaton/CellElement.h b/LibAutomaton/CellElement.h index 60b27e9..01c44f7 100644 --- a/LibAutomaton/CellElement.h +++ b/LibAutomaton/CellElement.h @@ -32,8 +32,6 @@ struct cellElement { int colIndex; int rowIndex; - bool value; - struct cellElement * nextCol; struct cellElement * nextRow; diff --git a/LibAutomaton/matrix.c b/LibAutomaton/matrix.c index 3b4477a..a0b9154 100644 --- a/LibAutomaton/matrix.c +++ b/LibAutomaton/matrix.c @@ -103,7 +103,7 @@ bool CreateMatrixElem(Matrix matrix, int ColPos, int RowPos){ if (error != 0){ - free(elem); + FreeCellElement(elem); return true; }else{ return false; @@ -246,4 +246,20 @@ void BasicPrintMatrix(Matrix matrix){ } printf("---END OF MATRIX---\n\n"); -} \ No newline at end of file +} + +Matrix freeMatrix(Matrix matrix){ + matrix.colCount = 0; + matrix.rowCount = 0; + /*il faut free les cellElements car FreeList ne peut pas le faire*/ + FreeList(matrix.cols); + FreeList(matrix.rows); + return matrix; +} + +/* todos : +*finir le freeMatrix +*chasser les bugs +*ecrire doc +*faire un print + opti pour que sli l'adapte avec sdl +*/ \ No newline at end of file diff --git a/LibAutomaton/matrix.h b/LibAutomaton/matrix.h index c3a38bc..797f5c8 100644 --- a/LibAutomaton/matrix.h +++ b/LibAutomaton/matrix.h @@ -79,5 +79,7 @@ Matrix SetMatrixDim(Matrix matrix,int nbCols,int nbRows); void BasicPrintMatrix(Matrix matrix); +Matrix freeMatrix(Matrix matrix); + #endif diff --git a/main.c b/main.c index bd8e0e6..6973351 100644 --- a/main.c +++ b/main.c @@ -15,17 +15,23 @@ int main(int argc, char **argv){ int Rule = 256; int N = 1; applyRules(matrix,Rule,N); - matrix = SetMatrixDim(matrix,1,2); + matrix = SetMatrixDim(matrix,3,3); BasicPrintMatrix(matrix); SetCellValue(matrix,0,0,true); - SetCellValue(matrix,0,0,true); + SetCellValue(matrix,0,1,true); + SetCellValue(matrix,0,2,true); BasicPrintMatrix(matrix); SetCellValue(matrix,0,0,false); - SetCellValue(matrix,0,0,false); + SetCellValue(matrix,0,1,false); BasicPrintMatrix(matrix); + + freeMatrix(matrix); return 0; } +/* todo +*modifier DeleteListContent avec sli +*/ \ No newline at end of file