I am trying to set up an array of structs within a struct in C. The size of the array is not known until runtime, so I have tried to define the array as dynamic. I have reduced my problem to the code shown below (there are a few more members in each struct, but don't pose a problem).
//struct definitions
struct intStream {
int test;
};
struct io {
struct inStream **inputStream;
};
// then proceed to main
int numDevices = 4; //(derived from number of devices found at runtime)
struct io *devices;
devices->inputStream = malloc(sizeof(struct inStream) * numDevices)
// Fails on
devices->inputStream[0]->test = 1;
I am still relatively new to C style programming, so my understanding of memory is not complete, but through some searching I have not been able to find alternate solutions to my problem besides the struct hack which aesthetically I do not like, as well as wanting the option to include more arrays in future.
devices. What do you think it is pointing at?