delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/06/27/12:16:12

From: "Christopher Nelson" <paradox AT gye DOT satnet DOT net>
To: <djgpp AT delorie DOT com>
Subject: Re: EOF reading pascal binary file
Date: Fri, 25 Jun 1999 19:02:40 -0600
Message-ID: <01bebf6f$96feab20$LocalHost@thendren>
MIME-Version: 1.0
X-Priority: 3
X-MSMail-Priority: Normal
X-Mailer: Microsoft Outlook Express 4.71.1712.3
X-MimeOLE: Produced By Microsoft MimeOLE V4.71.1712.3
Reply-To: djgpp AT delorie DOT com


>I'm using the following code to make a hexdump of a binary file I
>generated with a (turbo)pascal program. The strange thing is: I get an
>end-of-file signal before the end of the file is reached. So, in a file
>of 716 bytes, this method stops after having read 78 bytes, claiming it
>has reached the end of the file. It seems to work well for files
>generated with C++. And on the other hand, tpascal can deal with both
>pascal- and C++ files. No particular character seems to be at location
>78; with a hex-editor (which correctly shows all 716 bytes) I have 1A02
>there (for bytes with decimal offset 78-79, or 79-78, with byte
>inversion). Does anyone know what is going on here? Are there any other
>tricky details involved in reading pascal-generated files with a
>c-compiled program? Is there an online source about these?
>I'm using egcs 1.2.

character 0x1a is 26, the End Of File character.  make sure that the file is
opened in binary mode.  also, check which functions you are using to read
from the file.  normally, a text-mode file stores 26 at the end, right
before you close it.

also, there is no difference between a Turbo-Pascal generated file and a C++
generated file.  They are identical binary information.  The difference is
that DJGPP is very Unix-like, and Turbo-Pascal is very DOS-like.  Sometimes
that causes strange errors, because Unix files and DOS files have some
differences, especially text-mode files.

    -={C}=-




- Raw text -


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