From c44a06007ab1e8c90a067d90f492854886214586 Mon Sep 17 00:00:00 2001 From: Silas Schneider Date: Sun, 8 Nov 2026 15:49:07 +0100 Subject: [PATCH] Matrix Struktur und clearMatrix implementiert --- Startcode/matrix.c | 25 +++++++++++++++++++++++-- Startcode/matrix.h | 7 +++++++ 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/Startcode/matrix.c b/Startcode/matrix.c index ad00628..1340ba6 100644 --- a/Startcode/matrix.c +++ b/Startcode/matrix.c @@ -6,12 +6,33 @@ Matrix createMatrix(unsigned int rows, unsigned int cols) { - + + Matrix matrix; + + matrix.rows = rows; + matrix.cols = cols; + + matrix.buffer = calloc(rows * cols, sizeof(MatrixType)); + + if (matrix.buffer == NULL) { + + matrix.rows = 0; + matrix.cols = 0; + } + + return matrix; + } void clearMatrix(Matrix *matrix) { - + free(matrix->buffer); + + matrix->buffer = NULL; + matrix->rows = 0; + matrix->cols = 0; + + } void setMatrixAt(MatrixType value, Matrix matrix, unsigned int rowIdx, unsigned int colIdx) diff --git a/Startcode/matrix.h b/Startcode/matrix.h index cc640d1..241f2c7 100644 --- a/Startcode/matrix.h +++ b/Startcode/matrix.h @@ -7,6 +7,13 @@ typedef float MatrixType; // TODO Matrixtyp definieren +typdef struct { + + MatrixType *buffer; + unsigned int rows; + unsigned int cols; +}Matrix; + Matrix createMatrix(unsigned int rows, unsigned int cols); void clearMatrix(Matrix *matrix);