From 7c16f376481ca166c18d5adee7e0ef83876c9e77 Mon Sep 17 00:00:00 2001 From: Silas Schneider Date: Sun, 8 Nov 2026 16:48:42 +0100 Subject: [PATCH] createMatrix korrigiert und Tests bestanden --- Startcode/matrix.c | 11 +++++++++++ Startcode/matrix.h | 5 ++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/Startcode/matrix.c b/Startcode/matrix.c index 1340ba6..0e4ce6e 100644 --- a/Startcode/matrix.c +++ b/Startcode/matrix.c @@ -9,11 +9,22 @@ Matrix createMatrix(unsigned int rows, unsigned int cols) Matrix matrix; + // Prüfen, ob eine Dimension 0 ist + if (rows == 0 || cols == 0) { + matrix.rows = 0; + matrix.cols = 0; + matrix.buffer = NULL; + return matrix; + } + + // Zeilen und Spalten festlegen matrix.rows = rows; matrix.cols = cols; + // Speicher reservieren matrix.buffer = calloc(rows * cols, sizeof(MatrixType)); + //Prüfen ob die Speichereservierung fehlgeschlagen ist if (matrix.buffer == NULL) { matrix.rows = 0; diff --git a/Startcode/matrix.h b/Startcode/matrix.h index 241f2c7..0b2bc53 100644 --- a/Startcode/matrix.h +++ b/Startcode/matrix.h @@ -7,12 +7,11 @@ typedef float MatrixType; // TODO Matrixtyp definieren -typdef struct { - +typedef struct { MatrixType *buffer; unsigned int rows; unsigned int cols; -}Matrix; +} Matrix; Matrix createMatrix(unsigned int rows, unsigned int cols);