comp.lang.ada
 help / color / mirror / Atom feed
* FILE IO Error?
@ 2001-12-18 22:21 Ray
  2001-12-19 10:24 ` John R. Strohm
  2001-12-19 10:25 ` Preben Randhol
  0 siblings, 2 replies; 3+ messages in thread
From: Ray @ 2001-12-18 22:21 UTC (permalink / raw)


I am reading in some data from a file and despite reading in the data
successfully, I get this ADA.IO_EXCEPTIONS'CHILD_UNIT.END_ERROR which
means I am trying to read past the EOF.  Can someone explain why I get
this error or what I am not seeing?

thanks,

Ray

  
-----------------------------------------------------------------------------
   PROCEDURE load_data IS

      data_file : file_type;
      value : character;

   BEGIN

      open (data_file, in_file, "file.dat");

      IF NOT end_of_file (data_file) THEN
         FOR i IN 1 .. 8 LOOP

            -- Read in 8 character name.
            FOR j IN 1 .. 8 LOOP
               get (data_file, value);
               label_1 (i) (j) := value;
            END LOOP;

            -- Eat delimiter character.
            get (data_file, value);

            -- Read in 4 character name.
            FOR j IN 1 .. 4 LOOP
               get (data_file, value);
               label_2 (i) (j) := value;
            END LOOP;

         END LOOP;
      END IF;

      close (data_file);

   END load_data;
  
-----------------------------------------------------------------------------



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: FILE IO Error?
  2001-12-18 22:21 FILE IO Error? Ray
@ 2001-12-19 10:24 ` John R. Strohm
  2001-12-19 10:25 ` Preben Randhol
  1 sibling, 0 replies; 3+ messages in thread
From: John R. Strohm @ 2001-12-19 10:24 UTC (permalink / raw)


Just because you are programming in Ada doesn't mean you can ignore the
basics of debugging.

Add some text_io.put calls, to see what you're reading.

As coded, you appear to be planning on reading PRECISELY 8*(8+1+4) = 104
characters from your file.  You appear not to be expecting separators after
the second name in record i and the first name in record i+1, and you appear
not to be expecting any kind of record breaks.

Is this what you were planning on doing?

"Ray" <yarzepol@mindspring.com> wrote in message
news:3C1FC17F.B47D5CA8@mindspring.com...
> I am reading in some data from a file and despite reading in the data
> successfully, I get this ADA.IO_EXCEPTIONS'CHILD_UNIT.END_ERROR which
> means I am trying to read past the EOF.  Can someone explain why I get
> this error or what I am not seeing?
>
> thanks,
>
> Ray
>
>
> --------------------------------------------------------------------------
---
>    PROCEDURE load_data IS
>
>       data_file : file_type;
>       value : character;
>
>    BEGIN
>
>       open (data_file, in_file, "file.dat");
>
>       IF NOT end_of_file (data_file) THEN
>          FOR i IN 1 .. 8 LOOP
>
>             -- Read in 8 character name.
>             FOR j IN 1 .. 8 LOOP
>                get (data_file, value);
>                label_1 (i) (j) := value;
>             END LOOP;
>
>             -- Eat delimiter character.
>             get (data_file, value);
>
>             -- Read in 4 character name.
>             FOR j IN 1 .. 4 LOOP
>                get (data_file, value);
>                label_2 (i) (j) := value;
>             END LOOP;
>
>          END LOOP;
>       END IF;
>
>       close (data_file);
>
>    END load_data;
>
> --------------------------------------------------------------------------
---





^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: FILE IO Error?
  2001-12-18 22:21 FILE IO Error? Ray
  2001-12-19 10:24 ` John R. Strohm
@ 2001-12-19 10:25 ` Preben Randhol
  1 sibling, 0 replies; 3+ messages in thread
From: Preben Randhol @ 2001-12-19 10:25 UTC (permalink / raw)


On Tue, 18 Dec 2001 22:21:51 GMT, Ray wrote:
> I am reading in some data from a file and despite reading in the data
> successfully, I get this ADA.IO_EXCEPTIONS'CHILD_UNIT.END_ERROR which
> means I am trying to read past the EOF.  Can someone explain why I get
> this error or what I am not seeing?

Put in a couple of Put_Line that prints out what you read and I guess
you should see it.

>       open (data_file, in_file, "file.dat");
> 
>       IF NOT end_of_file (data_file) THEN

Why do you have the IF NOT above?

>          FOR i IN 1 .. 8 LOOP
>             -- Read in 8 character name.
>             FOR j IN 1 .. 8 LOOP
>                get (data_file, value);
>                label_1 (i) (j) := value;
>             END LOOP;
> 
>             -- Eat delimiter character.
>             get (data_file, value);

This looks like a point where errors can occur.
> 
>             -- Read in 4 character name.
>             FOR j IN 1 .. 4 LOOP
>                get (data_file, value);
>                label_2 (i) (j) := value;
>             END LOOP;
> 
>          END LOOP;
>       END IF;
> 
>       close (data_file);
> 
>    END load_data;

I would recommend as other has said to use Get_Line and then use Get on
this to get the values.

Preben
-- 
 ()   Join the worldwide campaign to protect fundamental human rights.
'||}
{||'                                           http://www.amnesty.org/



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2001-12-19 10:25 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-12-18 22:21 FILE IO Error? Ray
2001-12-19 10:24 ` John R. Strohm
2001-12-19 10:25 ` Preben Randhol

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