diff --git a/Startcode/matrix.c b/Startcode/matrix.c index 856cad8..4952d16 100644 --- a/Startcode/matrix.c +++ b/Startcode/matrix.c @@ -6,11 +6,36 @@ Matrix createMatrix(unsigned int rows, unsigned int cols) { + Matrix m; + m.rows = rows; + m.cols = cols; + + // Speicher reservieren und mit 0 initialisieren + m.buffer = (MatrixType *)calloc((size_t)rows * cols, sizeof(MatrixType)); + + // Falls Arbeitsspeicher voll ist + if (m.buffer == NULL) { + m.rows = 0; + m.cols = 0; + } + + return m; } void clearMatrix(Matrix *matrix) { + //prüfen ob pointer exisitert und ob es einen buffer gibt + if (matrix != NULL && matrix->buffer != NULL) + { + // Speicher freigeben + free(matrix->buffer); + + // Werte zurücksetzen + matrix->buffer = NULL; + matrix->rows = 0; + matrix->cols = 0; + } }