On Wednesday, 3 July 2013 at 20:37:24 UTC, captaindet wrote:
hi,
whilst converting some of my C code into D i got stuck.
in C:
typedef struct { /* info */ } INFO;
INFO info;
size_t checkio;
// read INFO from data file:
pf_datafile = fopen("datafile","rb");
checkio = fread((char *) &info, sizeof(info), 1, pf_datafile);
how do i do this in D? i'd like to avoid falling back to
calling C functions, but i cannot figure out how do this with
phobos functions. mind you, eventually the INFO struct might be
anywhere in the file, not only at the beginning.
cheers,
det
Take a look at http://dlang.org/phobos/std_file.html#.read
There is also http://dlang.org/phobos/std_file.html#.readText if
you wish to read a whole file as text.
When I tested it things like string didn't work but numbers did.
Maybe someone else here can help you if you need that.