»
 

Go Back   ResellerRatings Store Ratings > ResellerRatings Forums > Tech Support

Reply
 
LinkBack Thread Tools Display Modes
Old 06-18-2003, 12:16 PM   #1 (permalink)
Registered User
 
nukes's Avatar
 
Join Date: Oct 2002
Location: Scotland, UK
Posts: 2,946
nukes is on a distinguished road
Send a message via AIM to nukes Send a message via Yahoo to nukes
Reading a file into an array

Right, for the next stage of my project, I'm going to need some sort of map system. My plan was to use an array of Uint8 (Unsigned, 8 bit integers - an extra type provided by the SDL library)
If I define it in a class, like this:
Code:
class world {
public:
Uint8 map[200][200]; };
How would I read/write the data to/from a file on disk? Should I use low-level file-managment stuff or high-level? What sort of things do I need to do?
I'm just starting really with C++ and I'm not sure how I should handle something like this. I've done file IO in stuff like basic and pascal, but I can see from what I've read that this is going to be 100x harder.
Any points on where to start, or what I need to do?

__________________
_____
NuKeS
nukes is offline   Reply With Quote
Old 06-21-2003, 06:36 AM   #2 (permalink)
Registered User
 
strangerstill's Avatar
 
Join Date: Oct 2001
Posts: 1,565
strangerstill is on a distinguished road
Er... read the chapter on file I/O.

If you haven't got time for that, read the manual pages on open, write, read, and close. If Uint8 is a scalar type then write( fd, map, 200*200*sizeof Uint8 ) would be sufficient; otherwise you'll need to serialize the data in some way.
strangerstill is offline   Reply With Quote
Old 06-27-2003, 04:08 PM   #3 (permalink)
Registered User
 
nukes's Avatar
 
Join Date: Oct 2002
Location: Scotland, UK
Posts: 2,946
nukes is on a distinguished road
Send a message via AIM to nukes Send a message via Yahoo to nukes
Thanks. I am in your debt. I have a format worked out, and I have read the chapter on file I/O. Its just that it was a C book, and the C++ (fstreams.h) seems a hell of a lot nicer. I can just send it byte by byte and then read it in using the reverse routine. now I just have to spend some time drawing out the tiles, making a level editor, writing the loader routine and then make some levels for it. cheers.
__________________
_____
NuKeS
nukes is offline   Reply With Quote
Reply




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Most Active Discussions

Recent Discussions

All times are GMT -6. The time now is 02:54 PM.