#include #include #include #include "matrix.h" Matrix createMatrix(unsigned int rows, unsigned int cols){ /* unsigned int memory_depth = 0; memory_depth = rows * cols; //Meine Speichertiefe ist die Anzahl meiner Spalten mal die Reihen unsigned int memory_reservation = 0; memory_reservation = memory_depth * sizeof(MatrixType); //Nimmt die Speichertiefe mal die größe der einzelnen Speicherinhalte (float) Matrix.space = malloc(memory_reservation); //Reserviert den Speicher und gibt den Zeiger auf die erste Speicheradresse dem zeiger space (malloc "merkt" sich die Speichergröße an der adresse space) */ Matrix matrix; //Matrix ist der Datentyp (im struct bestimmt). wir brauchen hier aber eine lokale variable (!NIX GLOBAL!) daher ist matrix eine Variable vom Typ Matrix. matrix.rows = rows; matrix.cols = cols; matrix.space = malloc(rows * cols * sizeof(MatrixType)); if (matrix.space == NULL) { fprintf(stderr, "Error, matrix could not be created...\n"); matrix.rows = 0; matrix.cols = 0; } return matrix; } void clearMatrix(Matrix *matrix){ //*matrix greift auf die einträge im Struct Matrix zu if (matrix == NULL) { //Wenn Matrix schon leer ist, mach nichts return; } free(matrix->space); //Mit free wird die dynamische Speichergröße (die sich malloc gemerkt hat und mit der adresse von space verknüpft hat) wieder freigegeben matrix->space = NULL; //matrix->space = NULL ist das gleiche wie (*matrix).space = NULL / Setzt den Zeiger auf 0 matrix->rows = 0; //Wir greifen auf einen zeiger in struct zu deswegen (*matrix)[zeiger auf] .space[variable im struct] !Klammer weil . stärker bindet als *! matrix->cols = 0; } void setMatrixAt(MatrixType value, Matrix matrix, unsigned int rowIdx, unsigned int colIdx){ } MatrixType getMatrixAt(const Matrix matrix, unsigned int rowIdx, unsigned int colIdx){ } Matrix add(const Matrix matrix1, const Matrix matrix2){ } Matrix multiply(const Matrix matrix1, const Matrix matrix2){ }