home hardware prices news articles forums photos user reviews
Go Back   Tech Support Forums - TechIMO.com > PC Hardware and Tech > Webmastering and Programming
Ask a Tech Support Question (free)!

Reading a file into an array

Reply
Get bargains at  »  Dealighted.com
 
Thread Tools Search this Thread
Currently Active Users: 1573
Discussions: 200,951, Posts: 2,379,471, Members: 246,313
Old June 18th, 2003, 03:16 PM   Digg it!   #1 (permalink)
Ultimate Member
 
nukes's Avatar
 
Join Date: Oct 2002
Location: Scotland, UK
Posts: 3,221
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 June 21st, 2003, 09:36 AM     #2 (permalink)
Ultimate Member
 
strangerstill's Avatar
 
Join Date: Oct 2001
Posts: 1,542
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 June 27th, 2003, 07:08 PM     #3 (permalink)
Ultimate Member
 
nukes's Avatar
 
Join Date: Oct 2002
Location: Scotland, UK
Posts: 3,221
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 is offline   Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Most Active Discussions
The disrespect of Obama by Russian .. (39)
Is It Just Me? (2942)
Making Health Care Worse (178)
Wireless Televisions. (12)
CPU fan stops spinning randomly (8)
windows 7 problem (7)
Regular Build (11)
Is the PSU I received dead? (12)
radeon x850xt platinum & shader.. (6)
Print spooler problem (15)
windows vista security holes (10)
HIS HD5770 graphic card question (15)
Install XP pro and a Vista laptop ?.. (11)
Foreign voltage (10)
Recent Discussions
EVGA 9800 gtx help with finding a goo.. (11)
Regular Build (11)
Help with onclick and buttons (0)
Modern Warfare 2: Who Bought It? (63)
Virus advise (8)
My monitor won't turn on after instal.. (1)
Laptop with wireless problem. (3)
Internet Lost (3)
Dept. of HS: NSA 'Helped' Develop Vis.. (16)
windows vista security holes (10)
Point and Shoot Camera Suggestions. (4)
Multiple Restarts Required at Boot (2)
Ideal cheap graph card for PC-Gaming? (18)
radeon x850xt platinum & shader 3 (6)
Graphics Card Upgrade Question (4)
For Sale BFG GTX285 OC2 with 10 year .. (3)
How to convert MP3's (4)
Wireless Televisions. (12)
Hp Artist Edition + Matching Bag (0)
Asus P4G8X Mobo (6)
Xbox 360 GTA: SA disk error (1)
Is the PSU I received dead? (12)
windows 7 internet problem (5)
BSOD On Startup (ntoskrnl.exe) (2)
Print spooler problem (15)


All times are GMT -4. The time now is 01:49 AM.
TechIMO Copyright 2009 All Enthusiast, Inc.



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28