having not worked with C for a while I'm stuck with passing a single struct from an array of structs to a function by reference.
The code I have looks like this:
struct Sensor {
//ROM data
char romCRC[1];
char romSerial[6];
char romFamily[1];
};
const int maxSens = 10;
void Read_ROM(struct Sensor *sens){
char ROM[10];
for (k = 0; k<8; k++){
ROM[k] = read_byte();
sens->romFamily = ROM[0];
}
}
int main(){
struct Sensor Sensors[maxSens];
Read_ROM(&Sensors[0]);
}
What I expect it to do is:
- Create an array of 10 structs of type Sensor
- Pass the address of the first struct to the function Read_ROM
- Set the member romFamily of the struct Sensor[0] to ROM[0]
read_byte is tested and working. It does return 1 char.
When I try to compile I get this error:
#138 expression must be a modifiable lvalue
With 138 being the line number of:
sens->romFamily = ROM[0];
What is wrong here?