memcpy error

Hello.I have the following struct
1
2
3
4
5
6
7
8
9
    typedef struct{
        int nrecords;               //Number of records
        int recordsPerPage;         //Records Per Page
        int recordSize;             //Record size
        int PAGEID;                 //stores the first empty page
        int SLOT;                   //stores the first empty slot
        int sizeOfAttribute;        //store the sizeof Attribute
        char* attributes;     //stores the attributes of the table
    }REM_FileSubHeader;

and i use memcpy to pass the parametres and copy them to a ppData pointer.Here is how i copy them.
1
2
3
4
5
6
7
    memcpy(&ppData[0],&rfsh.nrecords,sizeof(int));
    memcpy(&ppData[4],&rfsh.recordsPerPage,sizeof(int));
    memcpy(&ppData[8],&rfsh.recordSize,sizeof(int));
    memcpy(&ppData[12],&rfsh.PAGEID,sizeof(int));
    memcpy(&ppData[16],&rfsh.SLOT,sizeof(int));
    memcpy(&ppData[20],&rfsh.sizeOfAttribute,sizeof(int));
    memcpy(&ppData[24],rfsh.attributes,rfsh.sizeOfAttribute);

It seems that everything is ok.I save them into a file using a function.The function is not made from me and it is correct.When i open this using the oposite memcpy like this
1
2
3
4
5
6
7
8
    memcpy(&rfsh.nrecords,&ppData[0],sizeof(int));
    memcpy(&rfsh.recordsPerPage,&ppData[4],sizeof(int));
    memcpy(&rfsh.recordSize,&ppData[8],sizeof(int));
    memcpy(&rfsh.PAGEID,&ppData[12],sizeof(int));
    memcpy(&rfsh.SLOT,&ppData[16],sizeof(int));
    memcpy(&rfsh.sizeOfAttribute,&ppData[20],sizeof(int));
    memcpy(rfsh.attributes,&ppData[24],rfsh.sizeOfAttribute);
    printf("Open ppData[24]=%c\n",ppData[24]);

i just can't see the rfh.attributes.My output is this: È÷ÿ¿o world asdqweasdqweNetBeansProjects/STORM/dist/Debug/GNU-MacOSX/storm
and it should be this:"Hello world asdqweasdqwe".I don't really know why.Can anyone help me?Thanks.
And what's wrong with default assignment? Copying fields in this instance is irrelevant and as a principle, wrong.
I know that this is not the best way to assign but this is what our professor wants to do.So.....By the way i found my mistake.Every string has the "\0" character which i didn't remember.
In printf("Open ppData[24]=%c\n",ppData[24]);, what is ppData?
Topic archived. No new replies allowed.