Using structs with arrays
Posted: 25 Jun 2012, 18:03
Hi, I want to use an array of structs where each struct can have an array of integers. I can set the values of everything ok, but when I try to access the values I get a crash and 'File error! -1' displayed on the screen.
The struct looks like this:
Then I initialise it all:
And later in the code:
I have also tried assigning the cellTargetIds[0] to an int variable with the same result. Any ideas anybody? Has anyone used structs like these successfully?
The struct looks like this:
Code: Select all
struct SensorHandler {
int id;
int cellTargetIds[2];
byte port;
};
Code: Select all
//-- create empty array:
SensorHandler emptyHandler;
ArrayInit(sensorHandlers,emptyHandler,NUM_OF_SENSORS);
//-- init all index-specific vals:
for (int i=0; i<NUM_OF_SENSORS; i++) {
for (int j=0; j<2; j++) {
sensorHandlers[i].cellTargetIds[j] = -1;
}
sensorHandlers[i].cellTargetIds[0] = i;
}
And later in the code:
Code: Select all
for (int i=0; i<NUM_OF_SENSORS; i++) {
for (int j=0; j<1; j++) {
NumOut(0,0,sensorHandlers[i].cellTargetIds[0]); //THIS LINE CAUSES THE PROGRAM CRASH
}
}