I'm relatively new to C. In my program, I have an array of struct, which get appended regularly.
I would like to write a function, which allows me to return the struct from an index to another in this array:
struct Log{
int sensorState;
int speed;
};
struct Log myEvent[10000];
Here is what I've done, but it is not working (SIGSEV
is thrown):
struct Log *getEvents(int from, int to){
struct Log *events[to-from+1];
for(int i=0; i<=to-from;i++){
events[i]->speed = myEvent[i].speed;
events[i]->sensorState = myEvent[i].sensorState;
}
return events
}
Feels like it would be so easy in Java or Python.. but I'm not able to do it in C, I tried so much things, and here I am.