Ok ich glaube ich habe es nun selbst entwickelt bekommen würde mich trotzdem freuen falls jemand nochmal die Richtigkeit überprüfen könnte ;).
C
#include <stdio.h>
#include <stdlib.h>
struct test_struct {
int a;
float b;
char *c;
};
typedef struct test_struct mystruct;
int main() {
mystruct *pm;
pm = (mystruct*) malloc(20 * sizeof(mystruct));
free(pm);
mystruct *str[20];
int i;
for (i = 0; i < 20; i++) {
str[i] = (mystruct*) malloc(100 * sizeof(mystruct));
int j;
for (j = 0; j < 100; j++) {
str[i][j].a = 1;
str[i][j].b = 2.0;
str[i][j].c = (char*) malloc(sizeof(char) * 100);
str[i][j].c[0] = 't';
str[i][j].c[1] = 'e';
str[i][j].c[2] = 's';
str[i][j].c[3] = 't';
str[i][j].c[4] = '\0';
}
}
for (i = 0; i < 20; i++) {
int j;
for (j = 0; j < 100; j++) {
free(str[i][j].c);
}
free(str[i]);
}
return 0;
}
Alles anzeigen