comp.lang.ada
 help / color / mirror / Atom feed
* Can I Do this – Help Badly Needed.
@ 2012-06-15 13:06 austin.obyrne
  2012-06-15 15:21 ` Adam Beneschan
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: austin.obyrne @ 2012-06-15 13:06 UTC (permalink / raw)


  

I want to write to two external files in turn from within the same program:

This is the first prompt,

  Ada.Text_IO.Put
  (Item => " Please enter the name of the unsorted file >");
  Ada.Text_IO.New_Line(2);
  Ada.Text_IO.Put
  (Item => " Call it UnSortedNumberFile_n.dat - for whatever 'n' may be >");
  Ada.Text_IO.New_Line(2);
  Ada.Text_IO.Put(Item => " ");
  Ada.Text_IO.Get_Line(Item => OutFileName,Last => OutNameLength);
  Ada.Text_IO.New_Line(2);
  Ada.Text_IO.Create(File => OutData,
  Mode => Ada.Text_IO.Out_File,Name => OutFileName(1 .. OutNameLength));

 Name given: UnsortedNumbers_n.dat 

Later on after some more computation in the same program I want to write out to another external file of a different name and I use the same prompt again that is only only slightly changed in the names.

Second prompt.

  Ada.Text_IO.Put
  (Item => " Please enter the name of the unsorted file >");
  Ada.Text_IO.New_Line(2);
  Ada.Text_IO.Put
  (Item => " Call it SortedNumberFile_n.dat - for whatever 'n' may be >");
  Ada.Text_IO.New_Line(2);
  Ada.Text_IO.Put(Item => " ");
  Ada.Text_IO.Get_Line(Item => OutFileName,Last => OutNameLength);
  Ada.Text_IO.New_Line(2);
  Ada.Text_IO.Create(File => OutData,
  Mode => Ada.Text_IO.Out_File,Name => OutFileName(1 .. OutNameLength)); 

Name given: SortedNumbers_n.dat 

Is this allowable?.

Your help would be greatly appreciated

-adacrypt




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

* Re: Can I Do this – Help Badly Needed.
  2012-06-15 13:06 Can I Do this – Help Badly Needed austin.obyrne
@ 2012-06-15 15:21 ` Adam Beneschan
  2012-06-15 15:54   ` austin.obyrne
  2012-06-15 15:36 ` austin.obyrne
  2012-06-16 13:36 ` Stephen Leake
  2 siblings, 1 reply; 5+ messages in thread
From: Adam Beneschan @ 2012-06-15 15:21 UTC (permalink / raw)


On Friday, June 15, 2012 6:06:12 AM UTC-7, austin...@hotmail.com wrote:
> I want to write to two external files in turn from within the same program:
> 
> This is the first prompt,
> 
>   Ada.Text_IO.Put
>   (Item => " Please enter the name of the unsorted file >");
>   Ada.Text_IO.New_Line(2);
>   Ada.Text_IO.Put
>   (Item => " Call it UnSortedNumberFile_n.dat - for whatever 'n' may be >");
>   Ada.Text_IO.New_Line(2);
>   Ada.Text_IO.Put(Item => " ");
>   Ada.Text_IO.Get_Line(Item => OutFileName,Last => OutNameLength);
>   Ada.Text_IO.New_Line(2);
>   Ada.Text_IO.Create(File => OutData,
>   Mode => Ada.Text_IO.Out_File,Name => OutFileName(1 .. OutNameLength));
> 
>  Name given: UnsortedNumbers_n.dat 
> 
> Later on after some more computation in the same program I want to write out to another external file of a different name and I use the same prompt again that is only only slightly changed in the names.
> 
> Second prompt.
> 
>   Ada.Text_IO.Put
>   (Item => " Please enter the name of the unsorted file >");
>   Ada.Text_IO.New_Line(2);
>   Ada.Text_IO.Put
>   (Item => " Call it SortedNumberFile_n.dat - for whatever 'n' may be >");
>   Ada.Text_IO.New_Line(2);
>   Ada.Text_IO.Put(Item => " ");
>   Ada.Text_IO.Get_Line(Item => OutFileName,Last => OutNameLength);
>   Ada.Text_IO.New_Line(2);
>   Ada.Text_IO.Create(File => OutData,
>   Mode => Ada.Text_IO.Out_File,Name => OutFileName(1 .. OutNameLength)); 
> 
> Name given: SortedNumbers_n.dat 
> 
> Is this allowable?.
> 
> Your help would be greatly appreciated

Is there a good reason to use OutData for both files?  I'd consider declaring a new File_Type object, Sorted_Out_Data or something (yes, I like putting underscores in names), for the sorted output, and Unsorted_Out_Data (instead of OutData) for the unsorted output.  The way you've written it, if you use Create on OutData, and then Create again on the same OutData, you'll get an exception unless you used Close on OutData in between.

Other than that, however, it's definitely allowable to write more than one text file from the same program, and to have multiple output text files open at the same time.  

                       -- Adam




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

* Re: Can I Do this – Help Badly Needed.
  2012-06-15 13:06 Can I Do this – Help Badly Needed austin.obyrne
  2012-06-15 15:21 ` Adam Beneschan
@ 2012-06-15 15:36 ` austin.obyrne
  2012-06-16 13:36 ` Stephen Leake
  2 siblings, 0 replies; 5+ messages in thread
From: austin.obyrne @ 2012-06-15 15:36 UTC (permalink / raw)


On Friday, June 15, 2012 2:06:12 PM UTC+1, austin...@hotmail.com wrote:
> I want to write to two external files in turn from within the same program:
> 
> This is the first prompt,
> 
>   Ada.Text_IO.Put
>   (Item => " Please enter the name of the unsorted file >");
>   Ada.Text_IO.New_Line(2);
>   Ada.Text_IO.Put
>   (Item => " Call it UnSortedNumberFile_n.dat - for whatever 'n' may be >");
>   Ada.Text_IO.New_Line(2);
>   Ada.Text_IO.Put(Item => " ");
>   Ada.Text_IO.Get_Line(Item => OutFileName,Last => OutNameLength);
>   Ada.Text_IO.New_Line(2);
>   Ada.Text_IO.Create(File => OutData,
>   Mode => Ada.Text_IO.Out_File,Name => OutFileName(1 .. OutNameLength));
> 
>  Name given: UnsortedNumbers_n.dat 
> 
> Later on after some more computation in the same program I want to write out to another external file of a different name and I use the same prompt again that is only only slightly changed in the names.
> 
> Second prompt.
> 
>   Ada.Text_IO.Put
>   (Item => " Please enter the name of the unsorted file >");
>   Ada.Text_IO.New_Line(2);
>   Ada.Text_IO.Put
>   (Item => " Call it SortedNumberFile_n.dat - for whatever 'n' may be >");
>   Ada.Text_IO.New_Line(2);
>   Ada.Text_IO.Put(Item => " ");
>   Ada.Text_IO.Get_Line(Item => OutFileName,Last => OutNameLength);
>   Ada.Text_IO.New_Line(2);
>   Ada.Text_IO.Create(File => OutData,
>   Mode => Ada.Text_IO.Out_File,Name => OutFileName(1 .. OutNameLength)); 
> 
> Name given: SortedNumbers_n.dat 
> 
> Is this allowable?.
> 
> Your help would be greatly appreciated
> 
> -adacrypt




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

* Re: Can I Do this – Help Badly Needed.
  2012-06-15 15:21 ` Adam Beneschan
@ 2012-06-15 15:54   ` austin.obyrne
  0 siblings, 0 replies; 5+ messages in thread
From: austin.obyrne @ 2012-06-15 15:54 UTC (permalink / raw)


On Friday, June 15, 2012 4:21:24 PM UTC+1, Adam Beneschan wrote:
> On Friday, June 15, 2012 6:06:12 AM UTC-7, austin...@hotmail.com wrote:
> > I want to write to two external files in turn from within the same program:
> > 
> > This is the first prompt,
> > 
> >   Ada.Text_IO.Put
> >   (Item => " Please enter the name of the unsorted file >");
> >   Ada.Text_IO.New_Line(2);
> >   Ada.Text_IO.Put
> >   (Item => " Call it UnSortedNumberFile_n.dat - for whatever 'n' may be >");
> >   Ada.Text_IO.New_Line(2);
> >   Ada.Text_IO.Put(Item => " ");
> >   Ada.Text_IO.Get_Line(Item => OutFileName,Last => OutNameLength);
> >   Ada.Text_IO.New_Line(2);
> >   Ada.Text_IO.Create(File => OutData,
> >   Mode => Ada.Text_IO.Out_File,Name => OutFileName(1 .. OutNameLength));
> > 
> >  Name given: UnsortedNumbers_n.dat 
> > 
> > Later on after some more computation in the same program I want to write out to another external file of a different name and I use the same prompt again that is only only slightly changed in the names.
> > 
> > Second prompt.
> > 
> >   Ada.Text_IO.Put
> >   (Item => " Please enter the name of the unsorted file >");
> >   Ada.Text_IO.New_Line(2);
> >   Ada.Text_IO.Put
> >   (Item => " Call it SortedNumberFile_n.dat - for whatever 'n' may be >");
> >   Ada.Text_IO.New_Line(2);
> >   Ada.Text_IO.Put(Item => " ");
> >   Ada.Text_IO.Get_Line(Item => OutFileName,Last => OutNameLength);
> >   Ada.Text_IO.New_Line(2);
> >   Ada.Text_IO.Create(File => OutData,
> >   Mode => Ada.Text_IO.Out_File,Name => OutFileName(1 .. OutNameLength)); 
> > 
> > Name given: SortedNumbers_n.dat 
> > 
> > Is this allowable?.
> > 
> > Your help would be greatly appreciated
> 
> Is there a good reason to use OutData for both files?  I'd consider declaring a new File_Type object, Sorted_Out_Data or something (yes, I like putting underscores in names), for the sorted output, and Unsorted_Out_Data (instead of OutData) for the unsorted output.  The way you've written it, if you use Create on OutData, and then Create again on the same OutData, you'll get an exception unless you used Close on OutData in between.
> 
> Other than that, however, it's definitely allowable to write more than one text file from the same program, and to have multiple output text files open at the same time.  
> 
>                        -- Adam

Many thanks for your great help.

Now that I know it is ok I would prefer to experiment separately getting it to work with multi files rather than mess about here.  There is some reason also for not going down that road as an alternative at the moment but it's to do with the algorithm.

It is very useful to know this now for future and I will perfect my skills separately on another occasion.  You have answered my question perfectly.

I am developing some powerful Ada-friendly sort programs that I will be uploading later for general perusal of the readership.

Regards and thanks again - adacrypt



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

* Re: Can I Do this – Help Badly Needed.
  2012-06-15 13:06 Can I Do this – Help Badly Needed austin.obyrne
  2012-06-15 15:21 ` Adam Beneschan
  2012-06-15 15:36 ` austin.obyrne
@ 2012-06-16 13:36 ` Stephen Leake
  2 siblings, 0 replies; 5+ messages in thread
From: Stephen Leake @ 2012-06-16 13:36 UTC (permalink / raw)


austin.obyrne@hotmail.com writes:

> Is this allowable?.

The best way to find out if some bit of Ada code is allowed is to
compile it. If you get an error that you don't understand, then posting
here is a good idea.

-- 
-- Stephe



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

end of thread, other threads:[~2012-06-16 13:36 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-06-15 13:06 Can I Do this – Help Badly Needed austin.obyrne
2012-06-15 15:21 ` Adam Beneschan
2012-06-15 15:54   ` austin.obyrne
2012-06-15 15:36 ` austin.obyrne
2012-06-16 13:36 ` Stephen Leake

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