Hallo Zusammen,
ich hab im folgendes Problem:
Ich brauche eine Strukur die eine dynamische 2D Matrix aufnimmt und will diese manipulieren.
Code:
Nun meine Frage: Ist der Code bis jetzt korrekt?
Wie kann ich auf mein 2D Arrray in einer Funktion (also über Pointer) zugreifen?
Danke für die Hilfe!
Schöne Grüße
ich hab im folgendes Problem:
Ich brauche eine Strukur die eine dynamische 2D Matrix aufnimmt und will diese manipulieren.
Code:
Code:
typedef struct{
int columns;
int rows;
int** Matrix;
}MATRIX;
int CreateMtz(MATRIX *Matrix)
{
if(Matrix->columns == 0||Matrix->rows==0||Matrix->Matrix==NULL)
return -1;
Matrix->Matrix = (int**)malloc(sizeof(int*)*Matrix->rows);
for(int i = 0;i<Matrix->columns;i++)
{
Matrix->Matrix[i] = (int*)malloc(sizeof(int)*Matrix->columns);
}
Matrix[0].Matrix[0][0] = 1;
return 0;
}
int main()
{
MATRIX myMtz;
myMtz.columns = 3;
myMtz.rows = 3;
CreateMtz(&myMtz);
//Bis hierher funktioniert das ganze noch zumindest kommt kein Fehler
printf("%i",myMtz.Matrix[0][0]); //Das funktioniert nicht mehr.
}
Nun meine Frage: Ist der Code bis jetzt korrekt?
Wie kann ich auf mein 2D Arrray in einer Funktion (also über Pointer) zugreifen?
Danke für die Hilfe!
Schöne Grüße