comp.lang.ada
 help / color / mirror / Atom feed
* End of a file
@ 2016-01-19  5:11 comicfanzine
  2016-01-19  5:52 ` J-P. Rosen
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: comicfanzine @ 2016-01-19  5:11 UTC (permalink / raw)


When the program is launched , it count a excess line .

And that's not a editor problem , the result is the same with severals .

So , there is 30 lines in this source code file .
However , the program count 31 .

Why ?


WITH Ada.Text_IO ;  USE Ada.Text_IO ;

Procedure count_nb_lines is

  this_file : File_type ;

  Last_line : Positive_Count := 1 ;

Begin

    Open
     (File => this_file ,
      Mode => In_file ,
      Name => "count_nb_lines.adb");

   loop
     set_line( this_file , Last_line );

     Last_line := Last_line + 1 ;
   end loop ;

    exception
      when End_Error => null;

   put_line ( "End of this file ? : "&Boolean'image( End_Of_File( this_file ) )  );
   put ( "Total of lines by Ada.Text_IO' s package : "&Positive_Count'Image( Last_line ) );

   Close( this_file );

end count_nb_lines ;

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

* Re: End of a file
  2016-01-19  5:11 End of a file comicfanzine
@ 2016-01-19  5:52 ` J-P. Rosen
  2016-01-19  7:20 ` comicfanzine
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 7+ messages in thread
From: J-P. Rosen @ 2016-01-19  5:52 UTC (permalink / raw)


Le 19/01/2016 06:11, comicfanzine@gmail.com a écrit :
> When the program is launched , it count a excess line .
> 
> And that's not a editor problem , the result is the same with severals .
> 
> So , there is 30 lines in this source code file .
> However , the program count 31 .
> 
> Why ?
> 
If you have 30 lines, set_line (30) is OK. It's set_Line (31) that
raises End_Error...


-- 
J-P. Rosen
Adalog
2 rue du Docteur Lombard, 92441 Issy-les-Moulineaux CEDEX
Tel: +33 1 45 29 21 52, Fax: +33 1 45 29 25 00
http://www.adalog.fr


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

* Re: End of a file
  2016-01-19  5:11 End of a file comicfanzine
  2016-01-19  5:52 ` J-P. Rosen
@ 2016-01-19  7:20 ` comicfanzine
  2016-01-19  8:02   ` Georg Bauhaus
  2016-01-19  8:43 ` comicfanzine
  2016-01-20  1:16 ` comicfanzine
  3 siblings, 1 reply; 7+ messages in thread
From: comicfanzine @ 2016-01-19  7:20 UTC (permalink / raw)


>If you have 30 lines, set_line (30) is OK. It's >set_Line (31) that raises End_Error... 

Ok , then why it's the case here :
" raised ADA.IO_EXCEPTIONS.END_ERROR : a-textio.adb:1900 "

There is only 26 lines , and the loop is suppose to stop at the end of the file . 

WITH Ada.Text_IO ;  USE Ada.Text_IO ;

Procedure count_nb_lines is

  this_file : File_type ;

  Last_line : Positive_Count := 1 ;

Begin

    Open
     (File => this_file ,
      Mode => In_file ,
      Name => "count_nb_lines.adb");

   loop exit when End_Of_File( this_file );
     skip_line( this_file , Last_line );

     Last_line := Last_line + 1 ;
   end loop ;

   put ( "Total of lines by Ada.Text_IO' s package : "&Positive_Count'Image( Last_line ) );

   Close( this_file );

end count_nb_lines ;


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

* Re: End of a file
  2016-01-19  7:20 ` comicfanzine
@ 2016-01-19  8:02   ` Georg Bauhaus
  0 siblings, 0 replies; 7+ messages in thread
From: Georg Bauhaus @ 2016-01-19  8:02 UTC (permalink / raw)


On 19.01.16 08:20, comicfanzine@gmail.com wrote:
>       skip_line( this_file , Last_line );

How many lines do you wish this call to skip on
each iteration?

-- 
"HOTDOGS ARE NOT BOOKMARKS"
Springfield Elementary teaching staff


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

* Re: End of a file
  2016-01-19  5:11 End of a file comicfanzine
  2016-01-19  5:52 ` J-P. Rosen
  2016-01-19  7:20 ` comicfanzine
@ 2016-01-19  8:43 ` comicfanzine
  2016-01-19  8:44   ` MM
  2016-01-20  1:16 ` comicfanzine
  3 siblings, 1 reply; 7+ messages in thread
From: comicfanzine @ 2016-01-19  8:43 UTC (permalink / raw)


>How many lines do you wish this call to skip on
>each iteration? 

Edit : Sorry , i posted the wrong code .

It just doesn't make sense , why the program create a extra line ?

The rignt number is 25 lines .

But it print 26 .

WITH Ada.Text_IO ;  USE Ada.Text_IO ;

Procedure count_nb_lines is

  this_file : File_type ;

  count : Positive_Count := 1 ;

Begin

    Open
     (File => this_file ,
      Mode => In_file ,
      Name => "count_nb_lines.adb");

   loop exit when End_Of_File( this_file );
     skip_line( this_file );
     count := count + 1 ;
   end loop ;

   put ( "Total of lines by Ada.Text_IO' s package : "&Positive_Count'Image( count ) );

   Close( this_file );

end count_nb_lines ;


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

* Re: End of a file
  2016-01-19  8:43 ` comicfanzine
@ 2016-01-19  8:44   ` MM
  0 siblings, 0 replies; 7+ messages in thread
From: MM @ 2016-01-19  8:44 UTC (permalink / raw)


On Tuesday, 19 January 2016 08:43:09 UTC, comicf...@gmail.com  wrote:
>   count : Positive_Count := 1 ;

Initialise this to zero, not one. Before you have read any lines, the count is zero.

M
-- 


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

* Re: End of a file
  2016-01-19  5:11 End of a file comicfanzine
                   ` (2 preceding siblings ...)
  2016-01-19  8:43 ` comicfanzine
@ 2016-01-20  1:16 ` comicfanzine
  3 siblings, 0 replies; 7+ messages in thread
From: comicfanzine @ 2016-01-20  1:16 UTC (permalink / raw)


MM ,

You're right , it work now .

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

end of thread, other threads:[~2016-01-20  1:16 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-01-19  5:11 End of a file comicfanzine
2016-01-19  5:52 ` J-P. Rosen
2016-01-19  7:20 ` comicfanzine
2016-01-19  8:02   ` Georg Bauhaus
2016-01-19  8:43 ` comicfanzine
2016-01-19  8:44   ` MM
2016-01-20  1:16 ` comicfanzine

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