matrix vollständig

This commit is contained in:
Björn 2025-11-17 18:30:06 +01:00
parent 8ac27e20c5
commit 86359bb37f

View File

@ -8,19 +8,19 @@
Matrix createMatrix(unsigned int rows, unsigned int cols) Matrix createMatrix(unsigned int rows, unsigned int cols)
{ {
Matrix matrix; Matrix matrix;
matrix.rows = rows;
matrix.cols = cols;
if (rows == 0 || cols == 0) {
matrix.buffer = NULL;
return matrix;
}
matrix.buffer = (MatrixType *)malloc(rows * cols * sizeof(MatrixType));
if (matrix.buffer == NULL)
{
matrix.rows = 0; matrix.rows = 0;
matrix.cols = 0; matrix.cols = 0;
matrix.buffer = NULL;
// Wenn die Dimensionen gültig sind, Speicher reservieren
if (rows > 0 && cols > 0)
{
matrix.buffer = (MatrixType *)malloc(rows * cols * sizeof(MatrixType));
if (matrix.buffer != NULL)
{
matrix.rows = rows;
matrix.cols = cols;
}
} }
return matrix; return matrix;
} }