From c99205afc2a54d1330f7ac0e254511814ac12615 Mon Sep 17 00:00:00 2001 From: Angelos Date: Thu, 12 Nov 2026 06:48:15 +0100 Subject: [PATCH] =?UTF-8?q?(create=20und=20clear=20Matrix=20hinzugef=C3=BC?= =?UTF-8?q?gt)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Startcode/matrix.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/Startcode/matrix.c b/Startcode/matrix.c index 856cad8..4952d16 100644 --- a/Startcode/matrix.c +++ b/Startcode/matrix.c @@ -6,11 +6,36 @@ Matrix createMatrix(unsigned int rows, unsigned int cols) { + Matrix m; + m.rows = rows; + m.cols = cols; + + // Speicher reservieren und mit 0 initialisieren + m.buffer = (MatrixType *)calloc((size_t)rows * cols, sizeof(MatrixType)); + + // Falls Arbeitsspeicher voll ist + if (m.buffer == NULL) { + m.rows = 0; + m.cols = 0; + } + + return m; } void clearMatrix(Matrix *matrix) { + //prüfen ob pointer exisitert und ob es einen buffer gibt + if (matrix != NULL && matrix->buffer != NULL) + { + // Speicher freigeben + free(matrix->buffer); + + // Werte zurücksetzen + matrix->buffer = NULL; + matrix->rows = 0; + matrix->cols = 0; + } }