comp.lang.ada
 help / color / mirror / Atom feed
* Got me stumped any idea?
@ 1997-10-11  0:00 Robert A. Thompson
  1997-10-13  0:00 ` SSWICM
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Robert A. Thompson @ 1997-10-11  0:00 UTC (permalink / raw)



I have been working on some stuff here recently and thought that Ada
would be a good compiler for the job.  Being it three years since I took
the class I thought I could brush up on my Ada, Familiarize myself with
the ada95 compiler we just put on our network, and get my work done. 
(kill three birds with one stone)  Well this little project is killing
three birds and one human.  ( I didn't realize what a couple of years
can do to one's rememberance of ada)  I have gone out on the web
searching for some pointers on ada95 b/c I was having some problems.  

I have this file:

With Ada.Text_IO; Use Ada.Text_IO;
With Ada.Strings.Unbounded; Use Ada.Strings.Unbounded;
Procedure Compare is

File1 		:	File_type;
File2 		:	File_type;
FileOut		:	File_type;
File1_line	:	String(1..80);

Begin
	Open(File1,In_File,"NetView.dat");
	Create(FileOut, Out_File, "Data.dat");
	
	While (Not End_Of_File(File1)) loop
		Get(File1,File1_line);
		Skip_Line(File1);
		Put_Line(FileOut,File1_Line);
		New_Line(FileOut);
	End Loop;

	Close(File1);
	Close(FileOut);
End Compare;

That I was gonna use to compare two files.  I thought I would check it
along the way to make sure I was doing things right.  I kept getting
some errors so as I said I went out onto the web and found some help. 
One of the AdaPages had this piece of code:


with Ada.Strings.Unbounded, Text_IO, Ustrings;
use  Ada.Strings.Unbounded, Text_IO, Ustrings;

procedure Put_Long is
  -- Print "long" text lines
  Input : Unbounded_String;
begin
  while (not End_Of_File) loop
    Get_Line(Input);
    if Length(Input) > 10 then
      Put_Line(Input);
    end if;
  end loop;
end Put_Long;



I thought it would be perfect..and looked exactly like what I needed.  I
couldn't compile it though.  It would keep giving me errors saying that
I was not passing the right paramters through the Get_line

Get_Line(File1,File1_line);

I corrected this with a Get

Get(File1,File1_line);

Now when I get the lines in and write them out from a simple text file. 
It goes to printing the lines strange into the file almost like

item1       blah blah
    item1       blah blah
        item1       blah blah
            item1       blah blah ....

This goes on untill it eventually wraps around I have yet to figure out
any of these.  problems


IF some one could let me in on why it is giving me these errors, and
evidently tell me what i am forgetting about basic file I/O I would
greatly Appreciate it.

Sincerely,

Robert A. Thompson




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

* Re: Got me stumped any idea?
  1997-10-11  0:00 Got me stumped any idea? Robert A. Thompson
@ 1997-10-13  0:00 ` SSWICM
  1997-10-14  0:00 ` Steve O'Neill
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: SSWICM @ 1997-10-13  0:00 UTC (permalink / raw)



"Robert A. Thompson" <stdrat01@unx1.shsu.edu> wrote:
>I thought it would be perfect..and looked exactly like what I needed.  I
>couldn't compile it though.  It would keep giving me errors saying that
>I was not passing the right paramters through the Get_line
The command you need is to use;
get_line(file1, file1_line, file1_line_length);

where;
file1_line_length: integer := 0;

This will pull the line and only fill the string with the right number
of characters. Might not be the best way, but i find it works..

Comments appreciated as to better ways..

Steven Adams






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

* Re: Got me stumped any idea?
  1997-10-11  0:00 Got me stumped any idea? Robert A. Thompson
  1997-10-13  0:00 ` SSWICM
@ 1997-10-14  0:00 ` Steve O'Neill
  1997-10-15  0:00 ` Anonymous
  1997-10-15  0:00 ` Matthew Heaney
  3 siblings, 0 replies; 5+ messages in thread
From: Steve O'Neill @ 1997-10-14  0:00 UTC (permalink / raw)



Robert A. Thompson wrote:
> 
> I have been working on some stuff here recently and thought that Ada
> would be a good compiler for the job. 

Good choice! :)

Well, the switch from Get to Get_Line was definitely a step in the
direction but your didn't go quite far enough.  If you read up on
Get_Line you'll notice that (in the case of reading from a file) it
requires 3 parameters.  The first is the file handle, the second is the
string into which the input is placed and the third is the number of
bytes actually read from the file for this 'line'.

This should solve the problem at hand...

Steve O'Neill




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

* Re: Got me stumped any idea?
  1997-10-11  0:00 Got me stumped any idea? Robert A. Thompson
                   ` (2 preceding siblings ...)
  1997-10-15  0:00 ` Anonymous
@ 1997-10-15  0:00 ` Matthew Heaney
  3 siblings, 0 replies; 5+ messages in thread
From: Matthew Heaney @ 1997-10-15  0:00 UTC (permalink / raw)



In article <343F77BF.18CA@unx1.shsu.edu>, stdrat01@unx1.shsu.edu wrote:


>I have this file:
>
>With Ada.Text_IO; Use Ada.Text_IO;
>With Ada.Strings.Unbounded; Use Ada.Strings.Unbounded;
>Procedure Compare is
>
>File1           :       File_type;
>File2           :       File_type;
>FileOut         :       File_type;
>File1_line      :       String(1..80);
>
>Begin
>        Open(File1,In_File,"NetView.dat");
>        Create(FileOut, Out_File, "Data.dat");
>        
>        While (Not End_Of_File(File1)) loop
>                Get(File1,File1_line);
>                Skip_Line(File1);
>                Put_Line(FileOut,File1_Line);
>                New_Line(FileOut);
>        End Loop;
>
>        Close(File1);
>        Close(FileOut);
>End Compare;

When you're reading text files (it's a pity Text_IO.File_Type isn't named
Text_IO.Text_File), it's a good idea to use Text_IO.Get_Line, to read in
the entire line.  The problem you're having is forgetting to include the
other parameter to that subprogram, the Last argument:

procedure Compare is

   File1, FileOut : File_Type;
  
   Line : String (1.. 80);
   Last : Natural;
begin
   ...
   while not End_Of_File (File1) loop
      Get_Line (File1, Line, Last);
      Put_Line (FileOut, Line (1 .. Last));
   end loop;
...

Will that solve your problem?  Get is probably not what you want, because
that just reads characters without respect to line terminators; I don't
think I've ever used it.  Read the RM and carefully compare Get and
Get_Line, and note the parameter profile of each procedure.

If you have any lines in your input file longer than 80, repost and I'll
help you with that.  (Let's try the simplest solution first.)

--------------------------------------------------------------------
Matthew Heaney
Software Development Consultant
<mailto:matthew_heaney@acm.org>
(818) 985-1271




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

* Re: Got me stumped any idea?
  1997-10-11  0:00 Got me stumped any idea? Robert A. Thompson
  1997-10-13  0:00 ` SSWICM
  1997-10-14  0:00 ` Steve O'Neill
@ 1997-10-15  0:00 ` Anonymous
  1997-10-15  0:00 ` Matthew Heaney
  3 siblings, 0 replies; 5+ messages in thread
From: Anonymous @ 1997-10-15  0:00 UTC (permalink / raw)



On Tue, 14 Oct 1997 09:28:34 -0400, Steve O'Neill
<oneills@top.monad.net> wrote:
[deleted stuff]
> direction but your didn't go quite far enough.  If you read up on
> Get_Line you'll notice that (in the case of reading from a file) it
> requires 3 parameters.  The first is the file handle, the second is the
> string into which the input is placed and the third is the number of
> bytes actually read from the file for this 'line'.
> 
> This should solve the problem at hand...
> 

I hate to see misinformation such as this handed out. Get_Line has 3
parameters:

File, type File_Type, the file object from which Get_Line reads

Item, type String, the string into which Get_Line places characters

Last, type Natural, which Get_Line sets to the index in Item into which
the last character was placed.

If no characters are placed into Item, Get_Line sets Last to
Item'First-1. Since Item'First may be as large as Positive'Last, Last is
clearly NOT the "number of bytes actually read from the file".

Jeff Carter  PGP:1024/440FBE21
My real e-mail address: ( carter @ innocon . com )
"We call your door-opening request a silly thing."
Monty Python & the Holy Grail

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




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

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

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1997-10-11  0:00 Got me stumped any idea? Robert A. Thompson
1997-10-13  0:00 ` SSWICM
1997-10-14  0:00 ` Steve O'Neill
1997-10-15  0:00 ` Anonymous
1997-10-15  0:00 ` Matthew Heaney

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