www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/10/03/00:45:20

From: Sigurdur Smarason <ssmaraso AT emerald DOT tufts DOT edu>
Newsgroups: comp.os.msdos.djgpp
Subject: newbie:problem with fread
Date: 3 Oct 1998 02:47:34 GMT
Organization: Tufts University
Lines: 46
Message-ID: <6v4386$c7t$1@news3.tufts.edu>
NNTP-Posting-Host: emerald.tufts.edu
X-Trace: news3.tufts.edu 907382854 12541 (None) 130.64.1.16
X-Complaints-To: news AT news DOT tufts DOT edu
X-Newsreader: TIN [UNIX 1.3 unoff BETA 970705; alpha OSF1 V4.0]
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

I just got djgpp v2.01, runing on a 486DX2-66 ms-dos/win3.1
(hey it's old but paid for :) ) 

I'm trying to read a binary file by passing a struct to fread, and
everything seems ok except when there is an odd number of shorts between
longs, then it skips two bytes after reading the short, then reads the
next long. this became aparent when I compared the values of num_records
and beyond to what they should be. Any ideas ?

thanks
Siggi


# include <stdio.h>

struct header_record{
       long file_type;
       short seq_index;
       short als_bottle;
       short replicate;
       short dir_ent_type;
       long dir_offset;
       long data_offset;
       long run_tbl_offset;
       long norm_offset;
       short extra_records;
       long num_records;
       short start_time;
       short end_time;
       long max_signal;
       long min_signal;
};


main(){

	FILE *data;
	clrscr();
	data=fopen("c:\\work\\data.ms","rb");
	header_record header;
	int size;
	size=fread(&header,sizeof(header),1,data);
	fclose(data);
}


- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019