Pete,
Sorry, but I’m still not sure I understand why you want to use a pointer inside your struct. Your code should work fine the way it stands. There is a more conventional way to initialize the contents of your structure, though:
typedef struct
{
char one[10];
int two;
int three;
}
record_type;
record_type record[8] = {
{"ADC1",2,3},
{"ADC2",3,6},
{"ADC3",4,9},
{"data",5,9}
};
If you want to have a pointer in a structure, you can declare it this way:
typedef struct
{
char one[10];
int *two;
int three;
}
record_type;
But you’ll also have to change the way you initialize it:
record_type record[8] = {
{"ADC1",(int *)NULL,3},
{"ADC2",(int *)NULL,6},
{"ADC3",(int *)NULL,9},
{"data",(int *)NULL,9}
};
You could also initialize the pointers to point to global or static ints in your program, or you could fill in the pointers in your program.
You can also pass a pointer to the whole structure into a function. Using your original structure, without any embedded pointers:
typedef struct
{
char one[10];
int two;
int three;
}
record_type;
record_type record[8] = {
{"ADC1",2,3},
{"ADC2",3,6},
{"ADC3",4,9},
{"data",5,9}
};
void this_func()
{
int i;
for (i = 0; i < 4; ++i)
that_func(&record[i]);
}
void that_func(record *r)
{
Serial.println(r->one);
Serial.println(r->two);
Serial.println(r->three);
r->two = r->two + 1; // increment value of 'two' element
}
Passing a pointer to a struct allows you to look at and change elements of that structure. The notation “r->one” is shorthand for “(*r).one”.
Regards,
-Mike