comp.lang.ada
 help / color / mirror / Atom feed
* Re: File I/O Problem/Question
  1997-06-12  0:00 File I/O Problem/Question Jim Marley
@ 1997-06-12  0:00 ` Stephen Leake
  1997-06-12  0:00 ` Anonymous
  1 sibling, 0 replies; 3+ messages in thread
From: Stephen Leake @ 1997-06-12  0:00 UTC (permalink / raw)



Jim Marley wrote:
> 
>         while not eof
>                 get_line(file, string, last)
> 
>                 while not eol
>                         get(file, int)
>                 end loop -- eol
>         end loop -- eof
> The program reads in the first string and first set of ints, it goes back
> to the top (inside the "while not eof"), skips the get_line and tries to
> "get" another int - causing a data exception because it's looking another
> string.

You need a Skip_Line after the second loop. Get (int) never reads the
line terminator, so the Get_Line read the line terminator of the "int
int" line, returning an empty string.

-- 
- Stephe




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

* File I/O Problem/Question
@ 1997-06-12  0:00 Jim Marley
  1997-06-12  0:00 ` Stephen Leake
  1997-06-12  0:00 ` Anonymous
  0 siblings, 2 replies; 3+ messages in thread
From: Jim Marley @ 1997-06-12  0:00 UTC (permalink / raw)



This is probably a simple problem, but I'm refreshing my knowledge of Ada
and it seems that I've forgotten more than I thought.

Problem:

I'm reading in a sequential text file, consisting of strings and integers. 
The file format is as follows:

string (variable length)
int int int int int (any number of integers)
string
int int int...
.. and so on.

I have it set up in two While loops (1. While not EOF, 2. While not EOL) -
here's the sudo code:

	while not eof
		get_line(file, string, last)
		
		while not eol
			get(file, int)
		end loop -- eol
	end loop -- eof
The program reads in the first string and first set of ints, it goes back
to the top (inside the "while not eof"), skips the get_line and tries to
"get" another int - causing a data exception because it's looking another
string.

Please let me know what I'm forgetting to do - and why it skips past the
get_line on the second pass.

Tks

Jim Marley 




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

* Re: File I/O Problem/Question
  1997-06-12  0:00 File I/O Problem/Question Jim Marley
  1997-06-12  0:00 ` Stephen Leake
@ 1997-06-12  0:00 ` Anonymous
  1 sibling, 0 replies; 3+ messages in thread
From: Anonymous @ 1997-06-12  0:00 UTC (permalink / raw)



On 12 Jun 1997 12:30:16 GMT, "Jim Marley" <jcmarle@qis.net> wrote:

> 
> 	while not eof
> 		get_line(file, string, last)
> 		
> 		while not eol
> 			get(file, int)
> 		end loop -- eol
> 	end loop -- eof
> The program reads in the first string and first set of ints, it goes back
> to the top (inside the "while not eof"), skips the get_line and tries to
> "get" another int - causing a data exception because it's looking another
> string.

Each line ends in a line terminator. We will assume that the string
you're using to read in the string lines is longer than any such line in
the file. In that case, Get_Line skips the line terminatior on the first
line. The inner loop then reads the integers (Get), but does not skipp
the line terminator on the second line. The second time Get_Line
executes, it reads a null line and skips the line terminator on the
second line. Then you try to read integers from the third line, which
causes the exception.

Solution: Add "Text_Io.Skip_Line (File => File);" after the inner loop.

Jeff Carter  PGP:1024/440FBE21
My real e-mail address: ( carter @ innocon . com )
"Now go away, or I shall taunt you a second time."
Monty Python & the Holy Grail

Posted with Spam Hater - see
http://www.compulink.co.uk/~net-services/spam/




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

end of thread, other threads:[~1997-06-12  0:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1997-06-12  0:00 File I/O Problem/Question Jim Marley
1997-06-12  0:00 ` Stephen Leake
1997-06-12  0:00 ` Anonymous

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