reading a structure (eg header info) from file

captaindet 2krnk at gmx.net
Wed Jul 3 13:37:28 PDT 2013


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  



More information about the Digitalmars-d-learn mailing list