I have a unsigned char pointer which contains a structure.Now I want to do the following
unsigned char *buffer ;
//code to fill the buffer with the relavent information.
int len = ntohs((record_t*)buffer->len);
where record_t structure contains a field called len.I am not able to do so and am getting the error.
error: request for member ‘len’ in something not a structure or union.
what am I doing wrong here?
If you're confident that you're doing the right thing (though this looks very hackish), you just have to get the operator precedence right:
ntohs( ((record_t*)buffer)->len );