Public Group

# fun with file i/o

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

## Recommended Posts

If you click here, you will be taken to page where you can download the source that pertains to this post. It is a small file, only 291 kb. I don't believe you need to understand 99% of the code to understand my problem. There is only a couple of lines that really relate to this problem. Here is a quick breakdown anyway. In main, just after I turn the cursor off, I initilize an object of type CSpriteBase. I then call writeFile(), then initilize an object of type CSpriteBaseR. The rest is just code for drawing the sprite, which isn't important, becasue it doesn't work anyway... :) The CSpriteBase object holds some info for a simple animation. In writeFile(), this info is written to a binary file. Then, the CSpriteBaseR object reads this info and hands it off to a CSprite object in hopes that it can be drawn. If you compile and run the code as is, you can take a look at stdout.txt and you will notice that everything written in writeFile() matches up with everything read in CSpriteBaseR. Now, go into main.cpp, and uncomment the line found in the following section of code found in writeFile()..
for(int c = 0; c < height; c++)
{
for(int d = 0; d < width; d++)
{
//pixel = ((Uint32*)base.frame[a].image->pixels)[d + c * (base.frame[a].pitch / 4)];
bFile.write((char*)&pixel, sizeof(Uint32));
}
}

Compile it and run it now. Take a look at stdout.txt. Everything in writeFile appears to be ok. But what happened when it was read back in? After the first pass through the loop, everything is gobblty gook. Uncommenting that line should not change the way the data is written to the file, nor how it is read. If uncommenting the line turns the variable pixel into crap, it should still be crap that is the size of Uint32. What is going on here? Any help is GREATLY appreciated. Peace Mr. Tie Dye

1. 1
2. 2
Rutin
19
3. 3
4. 4
5. 5

• 9
• 9
• 9
• 14
• 12
• ### Forum Statistics

• Total Topics
633298
• Total Posts
3011259
• ### Who's Online (See full list)

There are no registered users currently online

×