Typecasting char pointer to structure

Discussion in 'C++' started by venkatesh, Dec 6, 2003.

  1. venkatesh

    venkatesh Guest

    Hi Members,

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

    thanks in advance
    venkat
    venkatesh, Dec 6, 2003
    #1
    1. Advertising

  2. venkatesh

    lallous Guest

    "venkatesh" <> wrote in message
    news:...
    > 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
    lallous, Dec 6, 2003
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. LinuxGuy
    Replies:
    6
    Views:
    955
    Mike Wahler
    May 10, 2005
  2. b83503104
    Replies:
    1
    Views:
    3,491
    Eric Sosman
    Jun 21, 2004
  3. lovecreatesbeauty
    Replies:
    1
    Views:
    1,015
    Ian Collins
    May 9, 2006
  4. VasandGVD
    Replies:
    5
    Views:
    4,621
    CBFalconer
    Nov 28, 2008
  5. tim
    Replies:
    40
    Views:
    1,553
    Shao Miller
    Feb 1, 2012
Loading...

Share This Page