1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

copying and repopulating a struct instance with pointers

Discussion in 'C' started by ashwinkumar18, Oct 10, 2011.

  1. ashwinkumar18

    ashwinkumar18 New Member

    Oct 10, 2011
    Likes Received:
    Trophy Points:
    I am working on a tool in windows c++.
    I have a c++ structure which has the following format

    typedef struct node {
          int open;
          int version;
          const unsigned long long * data;
          char* flags;
    It is a handle to a binary file. I am doing API interception and I get this pointer from an internal API call being made by the application.

    Also The data field in the structure above is a pointer to instances of two structures laid out contiguously. The two structures are as follows.

     typedef struct header{
          unsigned int open;
          unsigned int version;
          unsigned long long int length;
        } _header;

     typedef struct body{
          unsigned int v1, v2, v3, v4, v5, v6, v7, v8, v9, v10;
          unsigned long long int ll1, ll2;
        } _body;

    I am able to access and print the data field as follows.

        _node* First=(node *)address;//Address is a pointer that i get from intercepting an application
        _header* nodeHeader=(_header*)First->data;
        char *bodyPtr=(char *)(nodeHeader+1);
        _body* nodeBody=(_body *)(bodyPtr);
        unsigned long long int offset=0;
        while(!(nodeBody->v1 & 1) && offset< nodeHeader->length)
    I want to write the struct node instance into a text file and be able to read it back into a struct instance later. What is the best way to do it? I want an answer in c++

    I want a c++ code because the code I am working on is in c++. The code i posted here has typedef because people who wrote the structure has written it in C.

Share This Page