readExact Problem
Daniel Keep
daniel.keep.lists at gmail.com
Fri May 25 01:07:36 PDT 2007
Charma wrote:
> well... i know... i am newbie with D T_T sorry...
That's alright; we all have to start from somewhere.
> this is the way i wrote it now and it seams to work perfectly:
>
> File index = new File(indexpath, FileMode.In);
> byte AmoundVFS;
> index.read(AmoundVFS);
> byte t;
You should probably use ubyte's for AmoundVFS and t. I don't imagine
you're going to have a negative number of entries, or negative length,
so you're restricting yourself to 127 entries/characters maximum.
Although, if you're conforming to an existing file format, best stick to
that :)
> char[][] VFSfile;
> VFSfile.length = AmoundVFS;
> for(int i=0;i<AmoundVFS;i++)
> {
> index.readExact(&t, 1);
> VFSfile[i].length = t;
> index.readExact(VFSfile[i].ptr, t);
> }
>
> AmoundVFS is saved in the very first byte of the file... i didn't mention it. Why i used uint for t the last time was because i thought that this could be the error since in Phobos it says that it want's a uint as parameter there...
> I hope this code is good now. If there is anything to imporve, let me know! thanks for the help!
The only other thing I can see is that index.readExact(&t,1) shouldn't
be necessary; you should be able to just use index.read(t), which does
basically the same thing, but is a bit cleaner.
-- Daniel
--
int getRandomNumber()
{
return 4; // chosen by fair dice roll.
// guaranteed to be random.
}
http://xkcd.com/
v2sw5+8Yhw5ln4+5pr6OFPma8u6+7Lw4Tm6+7l6+7D
i28a2Xs3MSr2e4/6+7t4TNSMb6HTOp5en5g6RAHCP http://hackerkey.com/
More information about the Digitalmars-d
mailing list