At the risk of sounding like the daft paper clip that used to give you advice in Microsoft Office...
"Hey, it looks like you want to access a structure field through a pointer and offset..."
In C you're forced to use something that's got loads of casts in it - there was an example of how to do that in a previous answer. As another answer mentioned you might have stucture alignment issues.
If you're using C++ you can use pointers to members which gives you all the goodness of offsets into a structure without running into problems with alignment.
Say you've got a structure B:
struct B
{
int i;
int j;
};
You can declare a pointer to either of the members using the following syntax:
int B::*p = &B::i;
Which says you can access one of the integers in the structure relative to the starting address of one of the structures. e.g:
B b;
B *pb = &b;
pb->*p = 100;
The last statement sets the i member of b to be 100, indirectly.
This is particularly handy when you want to iterate through an array of structures modifying a variable member of the structure...
e.g.
int B::*members[2] = { &B::i, &B::j };
You can then switch between members of the structure depending on which one of the members you access:
pb->*members[0] = 50;
It gets even cooler when you start using member function pointers, but that's another story.
Cheers,
Ash