comp.lang.ada
 help / color / mirror / Atom feed
From: hfrumblefoot@yahoo.com (Hambut)
Subject: Text_IO.End_Of_File Problem
Date: 25 Nov 2001 14:42:56 -0800
Date: 2001-11-25T22:42:56+00:00	[thread overview]
Message-ID: <fb75c450.0111251442.3e88ff5f@posting.google.com> (raw)

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.

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 :-)].  

I'd appreciate it if someone on here could have a peer at this and
give me a pointer as to where I'm going wrong.

The output I get from executing the code is:

"
 13
 13

raised ADA.IO_EXCEPTIONS.END_ERROR : a-textio.adb:394
"

Thanks in advance for any help.

Cheers,

Hambut.

=====Code Follows======

with Text_Io;
with Ada.Sequential_Io;
procedure Eof_Fails is

   package Io is new Ada.Sequential_Io( Character );

   Test_File_Name : constant String := "Test_fails";
   Sequential_File : Io.File_Type;
   Text_File : Text_Io.File_Type;

   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 );
    
-- These seem to work OK.
--       Failure_Characters : constant String := ( 1 => Ascii.CR,
--                                                 2 => Ascii.CR,
--                                                 3 => Ascii.LF,
--                                                 4 => Ascii.CR );

   C : Character;
begin
   -- First set up the test file
   --
   Io.Create( File => Sequential_File,
              Name => Test_File_Name );

   for I in Failure_Characters'First..Failure_Characters'Last loop
      Io.Write( File => Sequential_File,
                Item => Failure_Characters(I) );
   end loop;

   Io.Close( File => Sequential_File );

   -- Now try and read in as a text file
   --
   Text_Io.Open( File => Text_File,
                 Mode => Text_Io.In_File,
                 Name => Test_File_Name );

   while not Text_Io.End_Of_File( File => Text_File ) loop
      Text_Io.Get( File => Text_File,
                   Item => C );
      Text_Io.Put_Line( Integer'Image( Character'Pos(C)));
    end loop;

   Text_Io.Close( File => Text_File );
exception
   when others =>
      Text_Io.Close( File => Text_File );
      raise;
end Eof_fails;



             reply	other threads:[~2001-11-25 22:42 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-11-25 22:42 Hambut [this message]
2001-11-26  1:53 ` Text_IO.End_Of_File Problem 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
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