Reading uint[] array from binary file

Nico_C nicolas.charvin at libertysurf.fr
Mon Jan 22 11:57:16 PST 2007


Hi
I am trying to port a tool from C to D, and I have trouble to read data 
from binary file, using arrays.

in C, I use the following instructions

#define NBCHANNELSMAX = 4096
unsigned int spectrum[NBCHANNELSMAX];
fread(&spectrum, sizeof(unsigned int), nbChannels, file_in);

but in D, AFAIK, I can only read ubyte[], and the code:

uint arruint[];
arruint.length = nbChannels;
file_in.read(arruint);

gave me the following error:
function std.stream.Stream.read (ubyte[]) does not match parameter types 
(uint[])

So my question is:
1) is it possible to mimic the C fonction fread in order to get an array 
of uint, ushort, long, whatever the type ?
2) if not, how can i convert a ubyte[] to uint[], ushort[], etc..

Thanks in advance!
Best regards

nicolas


More information about the Digitalmars-d-learn mailing list