Re: Sequental IO and pointers
- From: ejijott@xxxxxxxxx
- Date: 27 Nov 2005 10:54:18 -0800
As an ad hoc solution my Save and Load procedures now work, as follows:
>
procedure Save(S: Storage; File: String) is
type ord is record
item: string(1..50);
len: integer :=-1;
count: integer := 0;
end record;
package OrdlistaIO is new Sequential_IO(ord);
use OrdlistaIO;
fh_ordlista:OrdlistaIO.File_type;
tnode:Storage;
ord_att_spara:ord;
begin
tnode:=S;
Create(fh_ordlista, Name=>file);
while tnode /= null loop
ord_att_spara.item(1 .. tnode.len):=tnode.item(1 ..
tnode.len);
ord_att_spara.len:=tnode.len;
ord_att_spara.count:=tnode.count;
Write(fh_ordlista, ord_att_spara);
tnode:=tnode.next;
end loop;
close(fh_ordlista);
end Save;
procedure Load(S: in out Storage; File: String) is
type ord is record
item: string(1..50);
len: integer :=-1;
count: integer := 0;
end record;
package OrdlistaIO is new Sequential_IO(ord);
use OrdlistaIO;
fh_ordlista:OrdlistaIO.File_type;
inläst_post:ord;
begin
Open(fh_ordlista, Name=>file, Mode=>In_file);
while not END_OF_FILE(fh_ordlista) loop
Read(fh_ordlista, inläst_post);
for i in 1 .. inläst_post.count loop
Append(S, inläst_post.item(1 .. inläst_post.len));
end loop;
end loop;
Close(fh_ordlista);
end Load;
<
The Append procedure adds my input record to the end of my linked list
and all is well... but still, something tells me there should be some
sort of prettier/faster implementation to use here... In the assignment
we are supposed to make functions to read both normal textfiles
(strings after eachother) and binary files... I really dont see how a
simple thing like this could benefit from using binary files.
.
- References:
- Sequental IO and pointers
- From: ejijott
- Re: Sequental IO and pointers
- From: Stephen Leake
- Re: Sequental IO and pointers
- From: ejijott
- Sequental IO and pointers
- Prev by Date: Re: Sequental IO and pointers
- Next by Date: Re: Allocated aligned arrays
- Previous by thread: Re: Sequental IO and pointers
- Index(es):
Relevant Pages
|