comp.lang.ada
 help / color / mirror / Atom feed
From: "chris.danx" <chris.danx@ntlworld.com>
Subject: Re: Ada Examples and Problems
Date: Wed, 11 Apr 2001 10:51:53 +0100
Date: 2001-04-11T10:51:53+01:00	[thread overview]
Message-ID: <DOVA6.3493$FD1.403553@news6-win.server.ntlworld.com> (raw)
In-Reply-To: ERFA6.2041$FY5.146015@www.newsranger.com


> >Basically the program should read in the owners from a file, then the
dogs.
> >The file is arranged owner, dog, owner, dog...
> So what *is* it doing?

I'm a complete numpty!  Sorry!

The program appears to read all the owners from the file.  When it goes to
output them on the screen it print's the first owner ok, but then hit's out
with a constraint error on the second.

The problem definitely comes from the way it reads the file's.  I've tested
the onwer_type completely.  It works on a sequential read but not on a
non-sequential read.

It should read the first record(owner), skip one(dog), read(owner)...

This is what i thought would achieve it.


   procedure read_owners (the_owners : out owner_array_type;
                          file       : in out file_type) is
      count   :   natural := 1;
      strm    :   stream_access;
      offset  :   positive;
   begin
      strm := stream(file);               -- get a stream from a file;

      set_index(file, 1);

      offset :=  (doggies.dog_type'size / 8);   -- calculate the offset of
next owner;


      while count <= 5 and not end_of_file(file) loop
         owners.owner_type'read(strm, the_owners(count));
         set_index(file, index(file) + positive_count(offset+1));
         ada.integer_text_io.put(integer(index(file)));
         ada.text_io.new_line;
         count := count + 1;
      end loop;
   end read_owners;


I reckon that it has something to do with the records size.  I'm not sure
what though.  Is the size of the record the same as the number of bytes
written per record?  Maybe this is it.


This is my first endevour into the world of non-sequential streams and i'm
still trying to get this right.  I just thought of something, I've tried
adding 1, not adding 1, but not taking 1 away.  I'll try that now!


Regards,
Chris





  parent reply	other threads:[~2001-04-11  9:51 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-04-10 13:38 Ada Examples and Problems chris.danx
2001-04-10 17:53 ` chris.danx
2001-04-10 17:57   ` chris.danx
     [not found] ` <ERFA6.2041$FY5.146015@www.newsranger.com>
2001-04-11  9:51   ` chris.danx [this message]
2001-04-11 15:34     ` Ted Dennison
2001-04-11 17:18       ` chris.danx
2001-04-11 17:43         ` chris.danx
2001-04-11 19:01           ` Marc A. Criley
2001-04-11 19:56             ` chris.danx
2001-04-12  1:41               ` tmoran
2001-04-12 15:28         ` Ted Dennison
2001-04-12 18:56           ` chris.danx
2001-04-12 19:01             ` chris.danx
2001-04-12 21:47             ` Ted Dennison
2001-04-13  8:40               ` chris.danx
2001-04-12  1:41     ` tmoran
2001-04-12 10:15       ` chris.danx
replies disabled

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