diff --git a/Startcode/matrix.c b/Startcode/matrix.c index ad00628..7875edb 100644 --- a/Startcode/matrix.c +++ b/Startcode/matrix.c @@ -6,12 +6,23 @@ Matrix createMatrix(unsigned int rows, unsigned int cols) { - + Matrix m; + m.rows = rows; + m.cols = cols; + m.data = (MatrixType*) calloc(rows * cols, sizeof(MatrixType)); // calloc, statt malloc benutzt, um direkt alle Werte mit 0 zu initialisieren + return m; } void clearMatrix(Matrix *matrix) { - + if(matrix == NULL){ // falls clearMatrix(NULL) aufgerufen wird, sonst würde es abstürzen, wenn mann direkt free(matrix->data) schreibt + return; + } + free(matrix->data); // matrix->data = (*matrix).data + matrix->data = NULL; // falls clearMatrix doppelt aufgerufen wird + matrix->rows = 0; // Matrix wird als komplett leer markiert + matrix->cols = 0; + } void setMatrixAt(MatrixType value, Matrix matrix, unsigned int rowIdx, unsigned int colIdx)