Register | Login
Views: 19364387
Main | Memberlist | Active users | ACS | Commons | Calendar | Online users
Ranks | FAQ | Color Chart | Photo album | IRC Chat
11-02-05 12:59 PM
0 user currently in Programming. | 3 guests
Acmlm's Board - I2 Archive - Programming - File reading problem [C++] | |
Add to favorites | "RSS" Feed | Next newer thread | Next older thread
User Post
Smallhacker

Green Birdo

SMW Hacking Moderator
Level: 68

Posts: 2060/2273
EXP: 2647223
For next: 81577

Since: 03-15-04
From: Söderhamn, Sweden

Since last post: 10 hours
Last activity: 9 hours
Posted on 09-05-05 09:31 PM Link | Quote
I'm trying to make a small game, since I need training in C++ programming. However, what's a game without levels? Therefore, I need code which reads the level data from a file.

(using fstream.h)

ifstream is;
is.open ("c:\\ZRO_lv.txt");
for (int yy=1;yy<26;yy++){
for (int xx=1;xx<61;xx++){
if (!rep){
is.get(rep);
is.get(readblk);
is.get(readcol);
}else{rep--;}
map[xx][yy].chr=Blockchar(readblk);
map[xx][yy].col=readcol;
}
}
is.close();

(File format, in case somebody wonders: Byte 1 = How many times to repeat the two following bytes. Byte 2 = Block number. Byte 3 = Block color)

However, for some reason, something goes wrong when it comes across a 0x0A byte, which seems to cause it to read junk instead of file data.

Can anyone tell me what the problem is?


(edited by Smallhacker on 09-05-05 12:31 PM)
HyperLamer
<||bass> and this was the soloution i thought of that was guarinteed to piss off the greatest amount of people

Sesshomaru
Tamaranian

Level: 118

Posts: 6864/8210
EXP: 18171887
For next: 211027

Since: 03-15-04
From: Canada, w00t!
LOL FAD

Since last post: 2 hours
Last activity: 2 hours
Posted on 09-05-05 10:51 PM Link | Quote
You've opened it in text mode. 0A is a newline character, so it may be converting it to 0D0A or something like that. I'm not sure how to open it in binary mode, though, since I just use fopen().

Also, I wrote a program like this and I found I had to do map[y][x] = blah.
Eponick

Blue Octorok
Level: 8

Posts: 27/37
EXP: 1760
For next: 427

Since: 09-02-05
From: Your closet

Since last post: 6 hours
Last activity: 6 hours
Posted on 09-06-05 01:19 AM Link | Quote
Just do
is.open("c:\\ZRO_lv.txt", ifstream::binary);

That should work
Smallhacker

Green Birdo

SMW Hacking Moderator
Level: 68

Posts: 2068/2273
EXP: 2647223
For next: 81577

Since: 03-15-04
From: Söderhamn, Sweden

Since last post: 10 hours
Last activity: 9 hours
Posted on 09-06-05 08:46 PM Link | Quote
Thanks. It works perfectly now.
Add to favorites | "RSS" Feed | Next newer thread | Next older thread
Acmlm's Board - I2 Archive - Programming - File reading problem [C++] | |


ABII


AcmlmBoard vl.ol (11-01-05)
© 2000-2005 Acmlm, Emuz, et al



Page rendered in 0.009 seconds.