reading a structure (eg header info) from file

2013-07-03 Thread captaindet
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

Re: reading a structure (eg header info) from file

2013-07-03 Thread Rikki Cattermole
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, sizeo

Re: reading a structure (eg header info) from file

2013-07-03 Thread Ali Çehreli
On 07/03/2013 01:37 PM, captaindet wrote: > 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); Just a reminder: The operation above is

Re: reading a structure (eg header info) from file

2013-07-03 Thread Jonathan M Davis
On Wednesday, July 03, 2013 15:37:28 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

Re: reading a structure (eg header info) from file

2013-07-04 Thread captaindet
thanks everyone for your help! i should have mentioned that i did play with std.stdio.File.readf and rawRead but was too thick to figure out a working solution. o i could not figure out how to make readf work with my self defined struct o same with rawRead. but here i understand my mistake now:

Re: reading a structure (eg header info) from file

2013-07-04 Thread bearophile
captaindet: as for the endianness, as i can oversee it now all potential users will sit on little-endian machines. the group of users is small, just our workgroup. If you are able to put a tag in your file that specifies the endianess, using Phobos it's not hard to convert the data to the ri