comp.lang.ada
 help / color / mirror / Atom feed
From: Patrick Hohmeyer <pi3_1415926536@yahoo.ca>
Subject: Re: Text_IO.End_Of_File Problem
Date: Sun, 25 Nov 2001 21:15:13 -0500
Date: 2001-11-25T21:15:13-05:00	[thread overview]
Message-ID: <uahM7.2663$3i2.402543@news20.bellglobal.com> (raw)
In-Reply-To: fb75c450.0111251442.3e88ff5f@posting.google.com

Hambut wrote :

> Hi,
> 
> I'm getting an exception with the attached code, and I can't see what
> I'm doing wrong, or why it's falling over.
> 
> The code basically:
> 
> 1.  Opens a file (sequential IO)
> 2.  Fills it with a sequence of Ascii.LF's and ASCII.CR's
> 3.  Closes it and reopens it as text_io
> 4.  reads each character in and outputs it's Ascii value to screen.
> 

<re-arangement>

>    Failure_Characters : constant String := ( 1 => Ascii.CR,
> 2 => Ascii.CR,
> 3 => Ascii.LF,
> 4 => Ascii.CR,
> 5 => Ascii.CR,
> 6 => Ascii.LF,
> 7 => Ascii.CR,
> 8 => Ascii.LF );

In Ada.Text_IO an end_of_line equals CR LF (as in windows)
So your file reads : CR, end_of_line, CR, end_of_line, end_of_line

> What *seems* to be happening is that text_io.end_of_file is not
> detecting the end of file properly in this case [or I've made some
> elementary error (having spent lots of time correcting my errors up to
> now I know which option my money's on :-)].

Get (Item : Character) skips all end_of_line's (and all end_of_page)
and reads the first "normal" character.

But end_of_file just tests the next character, so when the last character
of your file is an end_of_line, an EOF test doesn't prevent
Get (Item : Character) to skip the last end_of_line and depass the EOF.

To get rid of this you must test for an end_of_line and
when you encounter one, skip it with Skip_Line.

Does this pointer helps, or do you want a corrected code?

-- 
Patrick Hohmeyer



  parent reply	other threads:[~2001-11-26  2:15 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-11-25 22:42 Text_IO.End_Of_File Problem Hambut
2001-11-26  1:53 ` Jeffrey Carter
2001-11-26 12:30   ` Hambut
2001-11-26 16:50     ` Mark Biggar
2001-11-26 13:25   ` Hambut
2001-11-26  2:15 ` Patrick Hohmeyer [this message]
2001-11-26 12:36   ` Hambut
2001-11-26  2:35 ` Nick Roberts
2001-11-26 12:13   ` Hambut
2001-11-26 18:00     ` Nick Roberts
2001-11-27  9:51       ` Hambut
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox