Re: Sequental IO and pointers



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.

.



Relevant Pages

  • Re: curious about array initialization.
    ... understanding that its through the variable declaration that we ... By "inline string", I assume you mean a string literal. ... more than that you have implicit storage. ... Its a concept from computer programming. ...
    (comp.lang.c)
  • Re: Put Variables giving problems
    ... And - I would actually prefer to get it into a database that Access2000 ... >> phone as string ... > will be written to a Random file as a set of variable-size elements, ... > function for Random or Binary files. ...
    (microsoft.public.vb.syntax)
  • Re: curious about array initialization.
    ... understanding that its through the variable declaration that we ... By "inline string", I assume you mean a string literal. ... more than that you have implicit storage. ...
    (comp.lang.c)
  • Re: WORKING WITH STRINGS ?! THE FINAL CHALLENGE !
    ... the string should stay alive using the 'storage' pointer ... object Button1: TButton ...
    (alt.comp.lang.borland-delphi)
  • RE: XmlSerialization Object Memory Usage
    ... As you would expect, SimpleObject and ComplexObject are ... the same string objects. ... Hashtable storage = new Hashtable; ... private static ComplexObject BuildObject() ...
    (microsoft.public.dotnet.framework.performance)