martix.h fertig und matrix.c weiter

This commit is contained in:
MiraSchütz committed 2026-11-09 08:26:35 +01:00
1 parent 447e77a7bf
commit 37341ec9c3
2 files changed
+32

No files matched your search

+26
View File
@@ -6,11 +6,37 @@
Matrix createMatrix(unsigned int rows, unsigned int cols) Matrix createMatrix(unsigned int rows, unsigned int cols)
{ {
Matrix matrix;
if (rows == 0 || cols == 0) {
matrix.rows = 0;
matrix.cols = 0;
matrix.buffer = NULL;
return matrix;
}
matrix.buffer = malloc(rows*cols*sizeof(MatrixType));
if (matrix.buffer == NULL) {
matrix.rows = 0;
matrix.cols = 0;
matrix.buffer = NULL;
return matrix;
}
matrix.rows = rows;
matrix.cols = cols;
return matrix;
} }
void clearMatrix(Matrix *matrix) void clearMatrix(Matrix *matrix)
{ {
free(matrix->buffer);
matrix->buffer = NULL;
matrix->rows = 0;
matrix->cols = 0;
} }
+6
View File
@@ -5,6 +5,12 @@
typedef float MatrixType; typedef float MatrixType;
typedef struct Matrix{
unsigned int rows;
unsigned int cols;
MatrixType* buffer;
} Matrix;
// TODO Matrixtyp definieren // TODO Matrixtyp definieren