comp.lang.ada
 help / color / mirror / Atom feed
From: ejijott@gmail.com
Subject: Re: Sequental IO and pointers
Date: 27 Nov 2005 10:54:18 -0800
Date: 2005-11-27T10:54:18-08:00	[thread overview]
Message-ID: <1133117658.437818.318460@o13g2000cwo.googlegroups.com> (raw)
In-Reply-To: <1133115013.277922.147010@g14g2000cwa.googlegroups.com>

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.




      reply	other threads:[~2005-11-27 18:54 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-11-27  1:17 Sequental IO and pointers ejijott
2005-11-27  1:19 ` ejijott
2005-11-27 14:02 ` Stephen Leake
2005-11-27 18:10   ` ejijott
2005-11-27 18:54     ` ejijott [this message]
replies disabled

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