Unittest gemacht (Versuch2)

GREAT SUCCESS!
Matrix.c & Matrix.h abgeschlossen
This commit is contained in:
KohlerMaxi committed 2026-11-08 19:49:16 +01:00
1 parent fddc658da1
commit 8c8637bc48
2 files changed
+19 -11

No files matched your search

+19 -11
View File
@@ -14,20 +14,28 @@ Matrix createMatrix(unsigned int rows, unsigned int cols){
Matrix.buffer = malloc(memory_reservation); //Reserviert den Speicher und gibt den Zeiger auf die erste Speicheradresse dem zeiger buffer (malloc "merkt" sich die Speichergröße an der adresse buffer) Matrix.buffer = malloc(memory_reservation); //Reserviert den Speicher und gibt den Zeiger auf die erste Speicheradresse dem zeiger buffer (malloc "merkt" sich die Speichergröße an der adresse buffer)
*/ */
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 matrix = {0, 0, NULL}; //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.cols = cols; //Leere Matrix als Ausgangszustand erstellen
matrix.buffer = malloc(rows * cols * sizeof(MatrixType));
if (matrix.buffer == NULL) { // Prüfen, ob die Dimensionen gültig sind
fprintf(stderr, "Error, matrix could not be created...\n"); if (rows == 0 || cols == 0) {
matrix.rows = 0; fprintf(stderr, "Error, invalid matrix dimensions...\n");
matrix.cols = 0; return matrix;
matrix.buffer = NULL; }
}
return matrix; //Richtige Dimensionen speichern
matrix.rows = rows;
matrix.cols = cols;
matrix.buffer = malloc(rows * cols * sizeof(MatrixType)); //Reserviert den Speicher und gibt den Zeiger auf die erste Speicheradresse dem zeiger buffer (malloc "merkt" sich die Speichergröße an der adresse buffer)
if (matrix.buffer == NULL) {
fprintf(stderr, "Error, matrix could not be created...\n");
matrix.rows = 0;
matrix.cols = 0;
}
return matrix;
} }
BIN
View File
Binary file not shown.