delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/08/05/20:30:58

From: wagray AT taz DOT dra DOT hmg DOT gb (Walter Gray)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: How to make DJGPP treat an int as 16-bit in size.
Date: 4 Aug 1998 17:25:05 GMT
Organization: Defence Research Agency
Lines: 24
Message-ID: <6q7g5h$sv4$3@trog.dra.hmg.gb>
References: <Pine DOT SOL DOT 3 DOT 91 DOT 980803094454 DOT 23337A-100000 AT mercury> <Ex40Ez DOT 4rK AT fcshome DOT stoneham DOT ma DOT us>
Reply-To: wagray AT taz DOT dra DOT hmg DOT gb
NNTP-Posting-Host: taz.dra.hmg.gb
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

In article <Ex40Ez DOT 4rK AT fcshome DOT stoneham DOT ma DOT us>, fredex AT fcshome DOT stoneham DOT ma DOT us (Fred Smith) writes:
 :Goh Yong Kwang (s6606555 AT mercury DOT np DOT ac DOT sg) wrote:
 :
 :: I have some binary data files that are generated by a 16-bit DOS program
 :: which treat an int as 2 bytes.
 :
 :: Now I want to use DJGPP to write a program to read them but DJGPP thinks
 :: that an int should be 4 bytes (32-bits) huge.
 :
 :: The difference in size of int will cause the program to read the data 
 :: files incorrectly. Is there any easy way to make DJGPP treat int as 2 
 :: bytes?
 :
 :No.
 :
 :But you could write the code that reads it to use type 'short' instead,
 :then once you've got it into the short assign it to an int.
 :

Surely if they are binaries he should be reading them as chars? 

Walter

Disclaimer: My employer is not responsible for this stuff.
short int my_short_int_array[N];
	fread(my_short_int_array,  sizeof(short), N, file);

This is good for binary file only. The right method depend on how do You
write data.

- Raw text -


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