comp.lang.ada
 help / color / mirror / Atom feed
From: mheaney@ni.net (Matthew Heaney)
Subject: Re: Got me stumped any idea?
Date: 1997/10/15
Date: 1997-10-15T00:00:00+00:00	[thread overview]
Message-ID: <mheaney-ya023680001510972133400001@news.ni.net> (raw)
In-Reply-To: 343F77BF.18CA@unx1.shsu.edu


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




      parent reply	other threads:[~1997-10-15  0:00 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 message]
replies disabled

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