From 0a549b7e0d4ea00d720af6545e1573f3a25ab830 Mon Sep 17 00:00:00 2001 From: Lukas Weber Date: Sun, 23 Nov 2025 22:30:13 +0100 Subject: [PATCH] matrix.c fully functional, matrixTests returning no errors --- matrix.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/matrix.c b/matrix.c index 84a5450..4e9be5c 100644 --- a/matrix.c +++ b/matrix.c @@ -111,12 +111,14 @@ Matrix multiply(const Matrix matrix1, const Matrix matrix2) result.rows = 0; result.cols = 0; result.buffer = NULL; - if (matrix1.rows == matrix2.cols) { + + if (matrix1.cols != matrix2.rows) { + return result; + } + result.rows = matrix1.rows; result.cols = matrix2.cols; - if (matrix1.cols == matrix2.rows) { - result.buffer = malloc(result.rows * result.cols * sizeof(MatrixType)); for(int i = 0; i < result.rows; i++) { @@ -125,9 +127,8 @@ Matrix multiply(const Matrix matrix1, const Matrix matrix2) for(int k = 0; k < matrix1.cols; k++) { value += matrix1.buffer[i * matrix1.cols + k] * matrix2.buffer[k * matrix2.cols + j]; } - result.buffer[i * matrix1.cols + j] = value; + result.buffer[i * result.cols + j] = value; } - } } return result; } \ No newline at end of file