Dear Reader,
I'm having a pointer problem. I work within a program with an array of structs and these structs have various struct members. Some were in my program I need to access one of the the struct members with in this array by a pointer. My question is can some one show me how to do this.
Some part of my program are the following
struct pir_struct {
byte index ; // Index to the array of port structs.
byte state ; // State of the PIR statemachine (PIR passive infra-red sensor)
unsigned long movtime, movdelta ; // Movement detected state machine time variables
unsigned long nmvtime, nmvdelta ; // No-movement detected state machine time variables
byte PIRval ; // last read momentary value of the PIR
};
struct relay_struct{
byte index ; // Index to the array of port structs.
byte state ; // State of the relay which is on of off
unsigned long ontime, ondelta ; // Relay-on state machine time variables
unsigned long offtime,offdelta ; // Relay-off state machine time variables
byte *ptr2state ; // ptr to PIR struct->state element
};
pir pirlist[] = {{0, NMOV, 0,0 ,0,0,0}, // pirlist[] is an array or pir_stucts.
{2, NMOV, 0,0 ,0,0,0},
{3, MOV, 0,5000 ,0,0,0}};
relay relaylist[] = {{0, OFF, DUMMY,DUMMY ,0 ,0 ,0}, // Arraylist[] is an array or relay_stucts.
{4, OFF,0,5000,0,0, (byte*)&(pirlist[1]->state) },
{5, OFF,0,0000,0,0, (byte*)&(pirlist[2]->state) },
{6, OFF,0,0000,0,0, (byte*)&(termlist[1]->state) }};
I see that the text doesn't apear as is does in the editor my excuser for that.
I try to initialise the relaylist[1].ptr2state element which is a pointer with the address of pirlist[1].state.
According to what I know about pointers this can be done with the value : &(pirlist[1]->state) But Im not sure if this address really points to the element pirlist[1].state.
Can some one help me with this.
regards Oscar