generated from freudenreichan/info2Praktikum-NeuronalesNetz
Unittest gemacht (Versuch2)
GREAT SUCCESS! Matrix.c & Matrix.h abgeschlossen
This commit is contained in:
1 parent
fddc658da1
commit
8c8637bc48
2 files changed
+11
-3
No files matched your search
+11
-3
@@ -14,17 +14,25 @@ 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 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.
|
||||||
|
//Leere Matrix als Ausgangszustand erstellen
|
||||||
|
|
||||||
|
// Prüfen, ob die Dimensionen gültig sind
|
||||||
|
if (rows == 0 || cols == 0) {
|
||||||
|
fprintf(stderr, "Error, invalid matrix dimensions...\n");
|
||||||
|
return matrix;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Richtige Dimensionen speichern
|
||||||
matrix.rows = rows;
|
matrix.rows = rows;
|
||||||
matrix.cols = cols;
|
matrix.cols = cols;
|
||||||
matrix.buffer = malloc(rows * cols * sizeof(MatrixType));
|
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) {
|
if (matrix.buffer == NULL) {
|
||||||
fprintf(stderr, "Error, matrix could not be created...\n");
|
fprintf(stderr, "Error, matrix could not be created...\n");
|
||||||
matrix.rows = 0;
|
matrix.rows = 0;
|
||||||
matrix.cols = 0;
|
matrix.cols = 0;
|
||||||
matrix.buffer = NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return matrix;
|
return matrix;
|
||||||
|
|||||||
Executable
BIN
Binary file not shown.
Reference in new issue
Block a user