Creating array of structs
I'm having some trouble using an array of structs. I need to allocate sufficient memory then pass a pointer to this to a function that will create the array of structs, so that I can use the pointer later to search this array. It looks something like this (I've cut out much that is irrelevant):
This doesn't work at all, probably because I don't understand the syntax properly (I'm not a C or C++ programmer) or have perpetrated some other basic error(s). Would someone mind pointing the error(s) out?
void fill(Experiment * exptarr)
int count = 0;
// parse a file to extract the data for each of maxexpts Experiments,
// and attempt to copy the data to the array of structs
experiment.type = type;
exptarr[count] = experiment;
int main(int argc, char * argv)
Experiment * exptarr;
int maxexpts = 0;
// code to count the maximum number of experiments goes here,
// and updates maxexpts
exptarr = malloc(sizeof(Experiment) * maxexpts);
// expect to find that exptarr is an pointer to an array of Experiment structs...