By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,795 Members | 1,832 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,795 IT Pros & Developers. It's quick & easy.

Reading contents of a structure

P: 3
Please help:

I want to read out all the bytes of a structure and to write these to EEPROM i.e map the memory locations of the structure to EEPROM.

Can one use a pointer and increment it to point at each byte in a structure? I know how to do this using a pointer to an array, but not a pointer to a structure.

Need something along the lines of :

void TestRoutine (void)
struct Calib // Structure to hold calibration data
signed int DcOffset[3];
signed int CorrFctr[2][3][3];
} CalData;

unsigned int i;
struct Calib *st_ptr;

st_ptr = &CalData;

for (i=0; i <= SizeOfStructure, i++) do
printf("Value at this address is: %d \n", *st_ptr); // write contents at address pointed to by pointer
st_ptr++; // point to next byte in structure and repeat

I know something like

for (i = 0; i <= 3; i++)
printf("Value at this address is: %d \n",st_ptr->DcOffset[i]);

will work, but seems to me there should be a way to read each byte from the structure Calib without having to reference its members such as DcOffset ?

Nov 3 '06 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.