File reading

Started by quasist, January 11, 2010, 11:32:03 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

quasist

How to read binary files?

For instance there a "data\file.bin" and I need to read byte after byte from it?

Thanks in general. Just exporting level map to *.inc file is somewhat funny to me :)
Function Int Write_Signature()
Private
Begin
End;

josebita

You can try this:
http://wiki.bennugd.org/index.php?title=Save
I'm not sure if that's what you need, though.

Sandman

-- Sandman

quasist

#3
Could you help with some code?

I got
int map0[127][127];

and

//open file ????
handle=fopen(loadpath,O_READ);
for (yy=0;yy<128;yy++)
for (xx=0;xx<128;xx++)
// how to read one byte ????
fread(handle,map0[xx][yy]);
end;
end;
//release file ????
fclose(handle);  

Am I right?

But it crashed bennu...

So I suppose I have to load file contents to the memory, only then ripe bytes from it?
Function Int Write_Signature()
Private
Begin
End;

Windgate

INT fread ( <VOID POINTER data_pos> , <INT length> , <INT filehandle> )

With that you can set on length the number of bytes to read, 1 in your case.

The example you wrote reads int (4 bytes). Anyway it looks good, it must work reading integers from the file... ¿Does the file have enough bytes to read (128x128x4 bytes before end of file :P)?
Iván García Subero. Programador, profesor de informática, monitor de actividades culturales y presidente de TRINIT Asociación de Informáticos de Zaragoza. http://trinit.es

quasist

#5
160kb world in file = 400kb inc file = my DCB file is 2Mb :P

Switched map data from int to byte (I will not draw so much tiles anyway) and all worked :)
Function Int Write_Signature()
Private
Begin
End;