diff --git a/matrix.c b/matrix.c index ad00628..ba14bba 100644 --- a/matrix.c +++ b/matrix.c @@ -3,15 +3,26 @@ #include "matrix.h" // TODO Matrix-Funktionen implementieren - +// Matrix erstellen Matrix createMatrix(unsigned int rows, unsigned int cols) { - -} + Matrix matrix; + matrix.rows = rows; + matrix.cols = cols; + // Speicher allokieren + matrix.data = (double *)calloc(rows * cols, sizeof(double)); + return matrix; +} +// Matrix Speicher freigeben void clearMatrix(Matrix *matrix) { - + if (matrix != NULL && matrix->data != NULL) { + free(matrix->data); + matrix->data = NULL; + matrix->rows = 0; + matrix->cols = 0; + } } void setMatrixAt(MatrixType value, Matrix matrix, unsigned int rowIdx, unsigned int colIdx) diff --git a/matrix.h b/matrix.h index cc640d1..28187a8 100644 --- a/matrix.h +++ b/matrix.h @@ -6,6 +6,13 @@ typedef float MatrixType; // TODO Matrixtyp definieren +typedef struct +{ + int rows; + int cols; + int *data; + +} Matrix; Matrix createMatrix(unsigned int rows, unsigned int cols);