From: Peter Claessens Newsgroups: comp.os.msdos.djgpp Subject: EOF reading pascal binary file Date: Fri, 25 Jun 1999 17:17:10 +0200 Organization: KULeuvenNet Lines: 61 Message-ID: <37739D75.7473398A@psy.kuleuven.ac.be> NNTP-Posting-Host: marvin.kulnet.kuleuven.ac.be Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------040FEDFC5E1A3277B3E2B610" X-Trace: naxos.belnet.be 930323842 8970 134.58.127.3 (25 Jun 1999 15:17:22 GMT) X-Complaints-To: abuse AT belnet DOT be NNTP-Posting-Date: 25 Jun 1999 15:17:22 GMT X-Mailer: Mozilla 4.5 [en] (Win98; I) X-Accept-Language: nl-BE,nl,en Cache-Post-Path: marvin!unknown AT p100pw109 DOT psy DOT kuleuven DOT ac DOT be X-Cache: nntpcache 2.3.3 (see http://www.nntpcache.org/) To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com This is a multi-part message in MIME format. --------------040FEDFC5E1A3277B3E2B610 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit 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. ifstream inpfile(cmdarglist[0].c_str(),ios::in||ios::binary); unsigned short int x; int n; for(n=0;;n++) { inpfile.read((char*)&x,sizeof(x)); if (inpfile.eof()) { cout << endl << "End of file reached." << endl; break; } if (inpfile.fail()) { cerr << endl << "Error before end of file at byte " << n*sizeof(x) << endl; break; } else cout << hex << x << " "; } clog << "Read " << n*sizeof(x) << " bytes." << endl; --------------040FEDFC5E1A3277B3E2B610 Content-Type: text/x-vcard; charset=us-ascii; name="peter.claessens.vcf" Content-Transfer-Encoding: 7bit Content-Description: Card for Peter Claessens Content-Disposition: attachment; filename="peter.claessens.vcf" begin:vcard n:Claessens;Peter tel;fax:+32 16 32 60 99 tel;home:+32 16 29 17 28 tel;work:+32 16 32 59 30 x-mozilla-html:FALSE org:University of Leuven, Psychology department ;Laboratory for Experimental Psychology adr:;;Tiensestraat 102;Leuven;;B-3000;BELGIUM version:2.1 email;internet:peter DOT claessens AT psy DOT kuleuven DOT ac DOT be fn:Peter Claessens end:vcard --------------040FEDFC5E1A3277B3E2B610--