From 37341ec9c3c9968972e9b663550bfabb336635ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?MiraSch=C3=BCtz?= Date: Mon, 9 Nov 2026 08:26:35 +0100 Subject: [PATCH] martix.h fertig und matrix.c weiter --- Startcode/matrix.c | 28 +++++++++++++++++++++++++++- Startcode/matrix.h | 6 ++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/Startcode/matrix.c b/Startcode/matrix.c index ad00628..d926c4f 100644 --- a/Startcode/matrix.c +++ b/Startcode/matrix.c @@ -6,11 +6,37 @@ Matrix createMatrix(unsigned int rows, unsigned int cols) { - + Matrix matrix; + + if (rows == 0 || cols == 0) { + matrix.rows = 0; + matrix.cols = 0; + matrix.buffer = NULL; + + return matrix; + } + + matrix.buffer = malloc(rows*cols*sizeof(MatrixType)); + + if (matrix.buffer == NULL) { + matrix.rows = 0; + matrix.cols = 0; + matrix.buffer = NULL; + return matrix; + } + + matrix.rows = rows; + matrix.cols = cols; + + return matrix; } void clearMatrix(Matrix *matrix) { + free(matrix->buffer); + matrix->buffer = NULL; + matrix->rows = 0; + matrix->cols = 0; } diff --git a/Startcode/matrix.h b/Startcode/matrix.h index cc640d1..fea2a09 100644 --- a/Startcode/matrix.h +++ b/Startcode/matrix.h @@ -5,6 +5,12 @@ typedef float MatrixType; +typedef struct Matrix{ + unsigned int rows; + unsigned int cols; + MatrixType* buffer; +} Matrix; + // TODO Matrixtyp definieren