Reputation: 27
Can someone please tell me why I am getting an End_Error exception, I do not see how I am getting past the end of the file if I have a loop that opts out before it reaches this point. If there is an easy fix, I'd love to hear it, I've been stuck for a while and unbounded strings are not really my forte.
with Ada.Text_IO;
use Ada.Text_IO;
with Ada.Strings.Unbounded;
use Ada.Strings.Unbounded;
with Ada.Strings.Unbounded.Text_IO;
use Ada.Strings.UNbounded.Text_IO;
procedure checker is
InWord : Unbounded_String;
dictionary : File_Type;
count : Integer;
begin
Ada.Text_IO.Open
(File => dictionary, Mode => In_File, Name => "dictionary.txt");
loop
exit when End_of_File;
InWord := Get_Line(File => dictionary);
Put(InWord);
New_Line;
end loop;
end checker;
raised ADA.IO_EXCEPTIONS.END_ERROR : a-textio.adb:690
Upvotes: 1
Views: 381
Reputation: 1641
As stated in the ARM, End_Of_File without parameters refers to the current input file.
In your case, it just refers to the standard input and not to your file.
Considering Simon's answer and the behaviour you got, I think you use your program with a redirection of the standard input (something like "cat myFile.txt | checker"). Am I right ?
Upvotes: 2
Reputation: 25501
You have
exit when End_of_File;
but since you’re looking for EOF on the input file it should be
exit when End_Of_File(File => Dictionary);
I’m not sure why you see the effect you do - when I tried it, nothing happened until I typed a couple of RETs and then I got the End_Error
exception.
As you see, it’s nothing to do with strings, unbounded or otherwise!
Upvotes: 3