comp.lang.ada
 help / color / mirror / Atom feed
* Re: Reading a text file
  2000-10-08  0:00 Reading a text file stiletto
  2000-10-06  0:00 ` DPH
@ 2000-10-06  0:00 ` DPH
  1 sibling, 0 replies; 6+ messages in thread
From: DPH @ 2000-10-06  0:00 UTC (permalink / raw)


Note that the procedure "Read" is not a part of Ada.Text_IO.  That is why
it is not visible.  You probably want the procedure "Get" which is in
Ada.Text_IO.

Dave Head

stiletto@ryuji.net wrote:

> Hello All!
>
> How can I read text file?  Following program is supposed to read a text
> file and print out the contents of the file, but I got following error
> messages.
>
> Thanks in advance
>
> test.adb:13:01: "Read" is not visible
> test.adb:13:01: non-visible (private) declaration at a-textio.ads:348
> test.adb:13:01: non-visible declaration at a-stream.ads:58
> gnatmake: "test.adb" compilation error
>
> with Ada.Text_IO;
> use Ada.Text_IO;
>
> procedure test is
> Data_File : File_Type;
> Result_File : File_Type;
> St : String(1..100);
> begin
>
> Open(Data_File, In_File, "infile");
>
> while not End_Of_File(Data_File) loop
>   Read(Data_File, St);
>   Put_Line(St);
> end loop;
>
> end test;





^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Reading a text file
  2000-10-08  0:00 Reading a text file stiletto
@ 2000-10-06  0:00 ` DPH
  2000-10-06  0:00 ` DPH
  1 sibling, 0 replies; 6+ messages in thread
From: DPH @ 2000-10-06  0:00 UTC (permalink / raw)


Note that the procedure "Read" is not a part of Ada.Text_IO.  That is why
it is not visible.  You probably want the procedure "Get" which is in
Ada.Text_IO.  All the details are in A.10.1 of the Ada 95 Reference Manual.

Dave Head

stiletto@ryuji.net wrote:

> Hello All!
>
> How can I read text file?  Following program is supposed to read a text
> file and print out the contents of the file, but I got following error
> messages.
>
> Thanks in advance
>
> test.adb:13:01: "Read" is not visible
> test.adb:13:01: non-visible (private) declaration at a-textio.ads:348
> test.adb:13:01: non-visible declaration at a-stream.ads:58
> gnatmake: "test.adb" compilation error
>
> with Ada.Text_IO;
> use Ada.Text_IO;
>
> procedure test is
> Data_File : File_Type;
> Result_File : File_Type;
> St : String(1..100);
> begin
>
> Open(Data_File, In_File, "infile");
>
> while not End_Of_File(Data_File) loop
>   Read(Data_File, St);
>   Put_Line(St);
> end loop;
>
> end test;





^ permalink raw reply	[flat|nested] 6+ messages in thread

* Reading a text file
@ 2000-10-08  0:00 stiletto
  2000-10-06  0:00 ` DPH
  2000-10-06  0:00 ` DPH
  0 siblings, 2 replies; 6+ messages in thread
From: stiletto @ 2000-10-08  0:00 UTC (permalink / raw)



Hello All!

How can I read text file?  Following program is supposed to read a text 
file and print out the contents of the file, but I got following error 
messages.

Thanks in advance

test.adb:13:01: "Read" is not visible
test.adb:13:01: non-visible (private) declaration at a-textio.ads:348
test.adb:13:01: non-visible declaration at a-stream.ads:58
gnatmake: "test.adb" compilation error


with Ada.Text_IO;
use Ada.Text_IO;

procedure test is
Data_File : File_Type;
Result_File : File_Type;
St : String(1..100);
begin

Open(Data_File, In_File, "infile");

while not End_Of_File(Data_File) loop
  Read(Data_File, St);
  Put_Line(St);
end loop;

end test;




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Reading a text file
@ 2000-10-08  0:00 stiletto
  2000-10-08  0:00 ` Mathias Dolidon
  0 siblings, 1 reply; 6+ messages in thread
From: stiletto @ 2000-10-08  0:00 UTC (permalink / raw)



Hello All!

How can I read text file?  Following program is supposed to read a text 
file and print out the contents of the file, but I got following error 
messages.

Thanks in advance

test.adb:13:01: "Read" is not visible
test.adb:13:01: non-visible (private) declaration at a-textio.ads:348
test.adb:13:01: non-visible declaration at a-stream.ads:58
gnatmake: "test.adb" compilation error


with Ada.Text_IO;
use Ada.Text_IO;

procedure test is
Data_File : File_Type;
Result_File : File_Type;
St : String(1..100);
begin

Open(Data_File, In_File, "infile");

while not End_Of_File(Data_File) loop
  Read(Data_File, St);
  Put_Line(St);
end loop;

end test;




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Reading a text file
  2000-10-08  0:00 stiletto
@ 2000-10-08  0:00 ` Mathias Dolidon
  2000-10-08  0:00   ` Marin David Condic
  0 siblings, 1 reply; 6+ messages in thread
From: Mathias Dolidon @ 2000-10-08  0:00 UTC (permalink / raw)


stiletto@ryuji.net a �crit :
> 
> Hello All!
> 
> How can I read text file?  Following program is supposed to read a text
> file and print out the contents of the file, but I got following error
> messages.
> 
> Thanks in advance
> 
> test.adb:13:01: "Read" is not visible
> test.adb:13:01: non-visible (private) declaration at a-textio.ads:348
> test.adb:13:01: non-visible declaration at a-stream.ads:58
> gnatmake: "test.adb" compilation error
> 
> with Ada.Text_IO;
> use Ada.Text_IO;
> 
> procedure test is
> Data_File : File_Type;
> Result_File : File_Type;
> St : String(1..100);
> begin
> 
> Open(Data_File, In_File, "infile");
> 
> while not End_Of_File(Data_File) loop
>   Read(Data_File, St);
>   Put_Line(St);
> end loop;
> 
> end test;

Instead of "Read(Data_File, St)" write "Get_Line(Data_File, St)".

There's also another way to detecte the EOF :

--------
begin
loop
Get_Line(Data_File, St);
Put_Line(St);
end loop;

exception
  when end_error => close(Data_File);
end;
----------

Bye,
Mathias

-- 
http://www.mdlabs.ovh.org




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Reading a text file
  2000-10-08  0:00 ` Mathias Dolidon
@ 2000-10-08  0:00   ` Marin David Condic
  0 siblings, 0 replies; 6+ messages in thread
From: Marin David Condic @ 2000-10-08  0:00 UTC (permalink / raw)


Mathias Dolidon wrote:

> Instead of "Read(Data_File, St)" write "Get_Line(Data_File, St)".
>

From the ARM 10.1(49)

49.   procedure Get_Line(File : in  File_Type;
                           Item : out String;
                           Last : out Natural);

You've got the right idea, but you will need a "Last" actual parameter, which
indicates the last character in the string.

BTW, while the exception trap will, in fact, work for detecting EOF, I'd
consider it a bit abnormal. EOF is a condition you expect to arrive at sort
of like getting to the end of an array with an index. Most people would not
terminate an array scanning loop by trapping Constraint_Error, even though
it would work. Exceptions are generally considered an indication of some
unexpected condition or error. You would not usually use them for "normal"
program conditions.

MDC
--
======================================================================
Marin David Condic - Quadrus Corporation - http://www.quadruscorp.com/
Send Replies To: m c o n d i c @ q u a d r u s c o r p . c o m
Visit my web site at:  http://www.mcondic.com/

    "Giving money and power to Government is like giving whiskey
    and car keys to teenage boys."

        --   P. J. O'Rourke
======================================================================






^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2000-10-08  0:00 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-10-08  0:00 Reading a text file stiletto
2000-10-06  0:00 ` DPH
2000-10-06  0:00 ` DPH
  -- strict thread matches above, loose matches on Subject: below --
2000-10-08  0:00 stiletto
2000-10-08  0:00 ` Mathias Dolidon
2000-10-08  0:00   ` Marin David Condic

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