diff --git a/Startcode/matrix.c b/Startcode/matrix.c index ad00628..5493d7b 100644 --- a/Startcode/matrix.c +++ b/Startcode/matrix.c @@ -6,30 +6,50 @@ Matrix createMatrix(unsigned int rows, unsigned int cols) { + Matrix matrix = {NULL,rows,cols}; + if(rows != 0 && cols != 0){ + matrix.buffer = calloc(rows * cols, sizeof(MatrixType)); + if(matrix.buffer == NULL){ + matrix.rows = 0; + matrix.cols = 0; // alternativ Programm beenden mit exit -> so einfach dimensionslos + } + }else{ + matrix.rows = 0; + matrix.cols = 0; + } + return matrix; } void clearMatrix(Matrix *matrix) { - + free(matrix->buffer); + matrix->buffer = NULL; + matrix->rows = 0; + matrix->cols = 0; } void setMatrixAt(MatrixType value, Matrix matrix, unsigned int rowIdx, unsigned int colIdx) { - + if(matrix.rows > rowIdx && matrix.cols > colIdx){ + matrix.buffer[colIdx + rowIdx * matrix.cols] = value; + } } MatrixType getMatrixAt(const Matrix matrix, unsigned int rowIdx, unsigned int colIdx) { - + MatrixType testHelp = 0; + return testHelp; } Matrix add(const Matrix matrix1, const Matrix matrix2) { - + Matrix testHelp = {NULL, 0,0}; + return testHelp; } Matrix multiply(const Matrix matrix1, const Matrix matrix2) { - + Matrix testHelp = {NULL, 0,0}; + return testHelp; } \ No newline at end of file diff --git a/Startcode/matrix.h b/Startcode/matrix.h index cc640d1..9aead9a 100644 --- a/Startcode/matrix.h +++ b/Startcode/matrix.h @@ -7,6 +7,12 @@ typedef float MatrixType; // TODO Matrixtyp definieren +typedef struct{ + MatrixType* buffer; + unsigned int rows; + unsigned int cols; +}Matrix; + Matrix createMatrix(unsigned int rows, unsigned int cols); void clearMatrix(Matrix *matrix);