* Re: File IO
[not found] <348345B4.6E26@eng.clemson.edu>
@ 1997-12-02 0:00 ` Haug Buerger
1997-12-03 0:00 ` Jerry van Dijk
1 sibling, 0 replies; 2+ messages in thread
From: Haug Buerger @ 1997-12-02 0:00 UTC (permalink / raw)
li xianchang <xianchl@eng.clemson.edu> wrote:
>Hi,
>
>Does anyone who knows how to use file IO in ada 95? I am learning
>Ada95, and I have tried using Sequential_IO and Direct_IO, but when
>I use read(Input_File, Value), I cannot get the same one as in the
>data file. If you have some experience on this, would you mind giving
>me some suggestions? It will be better if you can attach a piece of
>code which works.
That's a trap i found, too. There is lots of good course
material for the base language but the predefind language
enviroment isn't covered very well.
Haug
Don't forget to remove REMOVEIT from my mail address.
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: File IO
[not found] <348345B4.6E26@eng.clemson.edu>
1997-12-02 0:00 ` File IO Haug Buerger
@ 1997-12-03 0:00 ` Jerry van Dijk
1 sibling, 0 replies; 2+ messages in thread
From: Jerry van Dijk @ 1997-12-03 0:00 UTC (permalink / raw)
In article <348345B4.6E26@eng.clemson.edu> xianchl@eng.clemson.edu writes:
>Does anyone who knows how to use file IO in ada 95? I am learning
>Ada95, and I have tried using Sequential_IO and Direct_IO, but when
>I use read(Input_File, Value), I cannot get the same one as in the
>data file. If you have some experience on this, would you mind giving
>me some suggestions? It will be better if you can attach a piece of
>code which works.
It might have been easier if you posted an example and what you expected
it to do, so we might have pointed out the error.
However, since you asked...
-- File I/O demo
with Ada.Text_IO;
with Ada.Sequential_IO;
procedure File_Demo is
Data_Size : constant Integer := 5;
Test_File : constant String := "test.dat";
type Data_Array is array (1 .. Data_Size) of Integer;
package Integer_File is new Ada.Sequential_IO (Data_Array);
Data_To_Write, Data_Read : Data_Array := (others => 0);
procedure Write_Data (File_Name : in String;
Data : in Data_Array) is
My_File : Integer_File.File_Type;
begin
Integer_File.Create (File => My_File,
Mode => Integer_File.Out_File,
Name => File_Name);
Integer_File.Write (File => My_File,
Item => Data);
Integer_File.Close (File => My_File);
end Write_Data;
procedure Read_Data (File_Name : in String;
Data : out Data_Array) is
My_File : Integer_File.File_Type;
begin
Integer_File.Open (File => My_File,
Mode => Integer_File.In_File,
Name => File_Name);
Integer_File.Read (File => My_File,
Item => Data);
Integer_File.Close (My_File);
end Read_Data;
begin
Data_To_Write := (1, 2, 3, 5, 8);
Write_Data (File_Name => Test_File,
Data => Data_To_Write);
Read_Data (File_Name => Test_File,
Data => Data_Read);
if Data_To_Write = Data_Read then
Ada.Text_IO.Put_Line ("Test succeded!");
else
Ada.Text_IO.Put_Line ("Test failed :-(");
end if;
end File_Demo;
--
-- Jerry van Dijk | Leiden, Holland
-- Consultant | Team Ada
-- Ordina Finance | jdijk@acm.org
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~1997-12-03 0:00 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <348345B4.6E26@eng.clemson.edu>
1997-12-02 0:00 ` File IO Haug Buerger
1997-12-03 0:00 ` Jerry van Dijk
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox