I'm a C beginners and I need help. I've a struct like this the following one:
struct {
char* name;
int level;
int spring_prob;
int population;
} Organism;
Organism with the same level have to be grouped into the same array to create a situation like that:
+++++ +++++++++++++++++++++++++++
| 0 | --> | organism_0 | organism_1 |
+++++ ++++++++++++++++++++++++++++++++++++++++
| 1 | | organism_2 | organism_3 | organism_4 |
+++++ ++++++++++++++++++++++++++++++++++++++++
| 2 | | organism_5 |
+++++ ++++++++++++++
org
In main i created an array to pointer to array of struct:
int main {
...
Organism *org[];
load_organism(org);
show(org);
return 0;
}
void load_organism (Organism *org[]){
Organism o[3];
o[0].name = "abc";
o[0].level = 0;
o[0].spring_prob = 25;
o[0].population = 300;
o[1].name = "def";
o[1].level = 0;
o[1].spring_prob = 25;
o[1].population = 20;
o[2].name = "ebs";
o[2].level = 0;
o[2].spring_prob = 25;
o[2].population = 20;
*org[0] = o;
}
void show (Organism* org[]) {
print("%s", org[0][0].name);
}
It crashes when i try to print the name of the first organism. I hope you could help me finding the error. Thanks in advance.
Organism *org[];as an error.int main {ist not valid.