generated from freudenreichan/info2Praktikum-NeuronalesNetz
Add createMatrix functionality
This commit is contained in:
parent
e5e92ad770
commit
2f3ddb1232
32
matrix.c
32
matrix.c
@ -7,12 +7,42 @@
|
|||||||
typedef struct Matrix {
|
typedef struct Matrix {
|
||||||
unsigned int xElement;
|
unsigned int xElement;
|
||||||
unsigned int yElement;
|
unsigned int yElement;
|
||||||
|
int ** data;
|
||||||
} Matrix;
|
} Matrix;
|
||||||
|
|
||||||
Matrix createMatrix(unsigned int rows, unsigned int cols)
|
Matrix createMatrix(unsigned int rows, unsigned int cols)
|
||||||
{
|
{
|
||||||
|
Matrix m;
|
||||||
|
m.xElement = rows;
|
||||||
|
m.yElement = cols;
|
||||||
|
m.data = NULL;
|
||||||
|
|
||||||
|
if(rows == 0 || cols == 0){
|
||||||
|
m.xElement = m.yElement = 0;
|
||||||
|
return m;
|
||||||
|
}
|
||||||
|
|
||||||
|
m.data = malloc(rows * sizeof *m.data);
|
||||||
|
|
||||||
|
if(!m.data){
|
||||||
|
m.xElement = m.yElement = 0;
|
||||||
|
return m;
|
||||||
|
}
|
||||||
|
for(unsigned int i = 0; i < rows; i++){
|
||||||
|
m.data[i] = malloc(cols * sizeof *m.data[i]);
|
||||||
|
|
||||||
|
if(!m.data[i]){
|
||||||
|
for(unsigned int j = 0; j < i; j++){
|
||||||
|
free(m.data[j]);
|
||||||
|
}
|
||||||
|
free(m.data);
|
||||||
|
m.data = NULL;
|
||||||
|
m.xElement = m.yElement = 0;
|
||||||
|
return m;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
void clearMatrix(Matrix *matrix)
|
void clearMatrix(Matrix *matrix)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user