Hi.
Could anyone please explain the following to me?
I have struct mapping a command on a certain memory area, and it's declared like this:
unsigned char outbuf[COMMAND_DATA_MAX_LENGTH]; struct odm_command *out_command = (struct odm_command *)outbuf;
The odm_command struct's last element is the array command_data[]. Now, I wanted to use the sprintf() function, and have it return the string to command_data[1]...command_data[n]. I've tested using:
sprintf(out_command->command_data[1], "Test");
That doesn't work. But if I first create a new variable that points to the 2nd slot in the command_data[] array, that works! Like this:
unsigned char *test = &out_command->command_data[1]; sprintf(test, "Test");
I've checked the memory allocation in AVR Studio, and this seems to work fine. But what I don't get is the use of * and &.
When casting the odm_command struct on the allocated memory area, I have to use * on the right side of the =. But when creating a variable that points to a slot in an array inside the struct, I have to use &. Can someone please explain the difference to me?