Archived

This topic is now archived and is closed to further replies.

Saveing the wrong memory??

This topic is 5589 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

ok I have a program that is trying to save a file well the first thing I save is a file id my serial for it and so I do with this
fwrite(&SERIAL,sizeof(%SERIAL),1,filevar); 
and in the file it equals "
%  ); 
" drop the "''s so then I put in the the number of integers after this like so
fwrite(&NumberofFrames,sizeof(&NumberofFrames),1,filevar); 
and I get "
|  
" then I save a ton of other integers so I go on
for (int q=0; q<38;q++)
ROTATION[q].Save(filevar);

and that function is

void Save(FILE *filevar)
{

        fwrite(&X,sizeof(&X),1,filevar);
        fwrite(&Y,sizeof(&Y),1,filevar);
        fwrite(&Z,sizeof(&Z),1,filevar);
} 
and I get "
œ  Skeleton Creation Tools p{J p{J x  Skeleton Creation To$   ''          Skeleton Creation Tools p{J p{J 0  Skeleton Creation Tools p{J p{J   Skeleton Creation Tools t×– t×– è  œ:– À<– ü>– ˆA–  O– ,R– <_– Üf–  j– 8n– ¨q– 4t–  €– Lƒ– ä…– T‰– à‹– h™– t– lientWidthÉ Color	clBtnFaceFont.Charô×– ô×– h  _CHARSET
Font.ColorclWindowTextFont.Heightõ	Font.Name
MS Sans Serif
Font.Style OldCreateOrderPositionpoScreenCenter
PixelsPerInch`
T); 
" and that is just not right... What could I do to fix this? thanks.

Share this post


Link to post
Share on other sites
The Fact that I expect the text editor to give me total raw giberish not some words from other parts of the program that are displayed as the window tital and names of objects used by c++ builder 5.5 the first two are correct and can be read back as the correct values the end is a bunch of crap from the compiler and my program that reads back as incorrect values I put in 1
and 5 and I should get something like "| " or something not "Skeleton Creation Tools" how could anything saving an interger come out with something like that out of just blind luck! Other then that mose of the numbers it saved in that teser where 0 so I don't see where the varitey came from. if that is anywhere near correct.

[edited by - Xero-X2 on August 26, 2002 8:08:29 PM]

Share this post


Link to post
Share on other sites
i get from my book (Although it is a rather old book)

size_t fwrite(const void *ptr, size_t size, size_t n, FILE *stream);

isn''t the size parameter for the sizeof(Variable); and the n parameter for the number of items in the array(for one item you use 1).

Is this wrong I got this information from my book, problem solving in C++ I got it from my brother he used it in his college course.

Share this post


Link to post
Share on other sites
It looks like you''re sending the wrong size to the function. For example, in the line:

fwrite(&X,sizeof(&X),1,filevar);

You are saying to write sizeof(&X) bytes to the file, but &X is an address which is 4 bytes (I think). So if X is anything other than 4 bytes long you are going to be writing either part of the value or garbage. Instead you should call the function like this:

fwrite(&X,sizeof(X),1,filevar);

So if X is 20 bytes the function will write 20 bytes. Just get rid of the &''s in sizeof().

- Never put passion above principle -

Share this post


Link to post
Share on other sites
I droped the &''s so now i have

fwrite(&X,sizeof(X),1,filevar);
fwrite(&Y,sizeof(Y),1,filevar);
fwrite(&Z,sizeof(Z),1,filevar);

but it gives me the same junk in the file and it still comes back when read as a bunch of random numbers.

Share this post


Link to post
Share on other sites