matrix vollständig
This commit is contained in:
parent
8ac27e20c5
commit
86359bb37f
22
matrix.c
22
matrix.c
@ -8,19 +8,19 @@
|
||||
Matrix createMatrix(unsigned int rows, unsigned int cols)
|
||||
{
|
||||
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.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;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user