Finished createMatrix and solved unit Test 2

This commit is contained in:
Jonas Stamm 2025-11-03 14:58:06 +01:00
parent 35cc6f2c7b
commit 772968dfef

View File

@ -1,4 +1,5 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h>
#include <string.h> #include <string.h>
#include "matrix.h" #include "matrix.h"
@ -6,11 +7,20 @@
Matrix createMatrix(unsigned int rows, unsigned int cols) Matrix createMatrix(unsigned int rows, unsigned int cols)
{ {
Matrix matrix; if (rows != 0 && cols != 0){
matrix.rows = rows; Matrix matrix;
matrix.cols = cols; matrix.rows = rows;
matrix.buffer = (float*) calloc(rows * cols, sizeof(float)); matrix.cols = cols;
return matrix; matrix.buffer = (float*) calloc(rows * cols, sizeof(float)); //belegt den speicherplatz mit calloc
return matrix;
}else{
printf("Nullgroesse der Matrix!!!\n");
Matrix matrix;
matrix.rows = 0;
matrix.cols = 0;
matrix.buffer = NULL;
return matrix;
}
} }
void clearMatrix(Matrix *matrix) void clearMatrix(Matrix *matrix)