No - it sees it as an array... in this case sizeof gives the correct value of memory allocated...Quote:
it sees it as the structure
Printable View
No - it sees it as an array... in this case sizeof gives the correct value of memory allocated...Quote:
it sees it as the structure
try this instead-
it will save the entire player database, including jim (im assuming jim is the SysOp)Code:FILE* hFile;
hFile = fopen("savefile.sav","w+b");
if(hFile != NULL){
fwrite(&jim,sizeof(PLYR),1,hFile);
fwrite(&pname[0],sizeof(PLYR),MAXLIST,hFile);
}
fclose(hFile);
I have actually changed my code so it looks more like that (with MAXLIST, not 1 and PLYR not pname) and it prodices exactly the same results.
One of the read reasons I did this is because when I read the data back in it appears some sort of corruption occured and I thought it might have been because there was a problem in the way I did it. However I get exactly the same 'corruption' when I do it 'your way' so I don't
think the problem is in the saving/restoring of the data, it must be some thing else.
It reads the first two records in OK and the results are correct in that the values are doubled
(the data is effectively been processed twice). Then the next seven records are 'screwed up'
ie rubbish data values, then they are printed OK, as are the other 200 odd records but not
the double values just singuler.(looks likethey were not processed).
Futher investigations reveas only the first 3 player names are correct then the next 7 have their first 3 letter missing and the rest come out as blank "".
Just thinking out loud really, this is going to take some sorting!!
Will report back later!!
I guess I should have used a loop and printfs, which I will have to use to debug it anyway :)
Here is a dedug output after it has reread the file
The first two records are fine then on the third the interger values are huge eg 134217728 far to big.Code:<Phillip><-1500.000000><0.000000><0.000000><9><3><3><3><9><9><9><0>
<Brian><452.500000><0.000000><0.000000><24><11><11><11><24><24><24><2>
<Slothie><5700.000000><0.000000><0.000000><134217728><134217728><134217728><67108864><458752><0><0><0>
<liam><0.000000><0.000000><0.000000><3072><3072><3072><3072><6144><6144><1280><2048>
<rew><0.000000><0.000000><0.000000><1536><1536><1536><1536><6144><6144><512><256>
Then the 4th and 5th names William and Andrew have the first three letters missing.
It seems it is some sort of low level data alignment problem?
Any ideas?
I can always do it with printd and scanfs but I would like to know why this way does not work.
I have a vague recollection that you can specify how the data is alligned someway?