Typecasting char pointer to structure

V

venkatesh

Hi Members,

I need to convert Char Pointer to a Structure.How Can i typecast this.

thanks in advance
venkat
 
L

lallous

venkatesh said:
Hi Members,

I need to convert Char Pointer to a Structure.How Can i typecast this.

thanks in advance
venkat

struct MyStruct
{
int a, b, c;
};

int main()
{
char *ptr;
MyStruct *pstruct;

// C++ casting
pstruct = reinterpret_cast<MyStruct *>(ptr);
// or C style casting:
pstruct = (MyStruct *)ptr;

return 0;
}

Regards,
Elias
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,012
Latest member
RoxanneDzm

Latest Threads

Top