comp.lang.ada
 help / color / mirror / Atom feed
* Text Files
@ 2000-05-23  0:00 Karlene
  2000-05-23  0:00 ` Marin D. Condic
                   ` (4 more replies)
  0 siblings, 5 replies; 14+ messages in thread
From: Karlene @ 2000-05-23  0:00 UTC (permalink / raw)


How can you create a text file to be written to and read from (seperatley)
in an ada program where the file name is inputed from the user??







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

* Re: Text Files
  2000-05-23  0:00 Text Files Karlene
  2000-05-23  0:00 ` Marin D. Condic
  2000-05-23  0:00 ` Cameron McShane
@ 2000-05-23  0:00 ` Ted Dennison
  2000-05-23  0:00 ` David Freshwater
  2000-05-23  0:00 ` Robert Dewar
  4 siblings, 0 replies; 14+ messages in thread
From: Ted Dennison @ 2000-05-23  0:00 UTC (permalink / raw)


In article <8gdguu$f9v$1@news.cowan.edu.au>,
  "Karlene" <kejohnso@student.ecu.edu.au> wrote:
> How can you create a text file to be written to and read from
(seperatley)
> in an ada program where the file name is inputed from the user??

The package Ada.Text_IO has routines to allow you to perform both parts
of this action. For further details, I suggest you consult your Ada
textbook or ask your instructor. This is really basic stuff.

Also, you ought to bookmark http://www.adapower.com


--
T.E.D.

http://www.telepath.com/~dennison/Ted/TED.html


Sent via Deja.com http://www.deja.com/
Before you buy.




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

* Re: Text Files
  2000-05-23  0:00 Text Files Karlene
                   ` (2 preceding siblings ...)
  2000-05-23  0:00 ` Ted Dennison
@ 2000-05-23  0:00 ` David Freshwater
  2000-05-23  0:00 ` Robert Dewar
  4 siblings, 0 replies; 14+ messages in thread
From: David Freshwater @ 2000-05-23  0:00 UTC (permalink / raw)


Karlene,

            Read your text.....twit
David

P.S You ask this question with one week to go, PLEASE!!!!!!

Karlene <kejohnso@student.ecu.edu.au> wrote in message
news:8gdguu$f9v$1@news.cowan.edu.au...
> How can you create a text file to be written to and read from (seperatley)
> in an ada program where the file name is inputed from the user??
>
>
>






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

* Re: Text Files
  2000-05-23  0:00 Text Files Karlene
                   ` (3 preceding siblings ...)
  2000-05-23  0:00 ` David Freshwater
@ 2000-05-23  0:00 ` Robert Dewar
  2000-05-24  0:00   ` Marin D. Condic
  4 siblings, 1 reply; 14+ messages in thread
From: Robert Dewar @ 2000-05-23  0:00 UTC (permalink / raw)


In article <8gdguu$f9v$1@news.cowan.edu.au>,
  "Karlene" <kejohnso@student.ecu.edu.au> wrote:
> How can you create a text file to be written to and read from
(seperatley)
> in an ada program where the file name is inputed from the
user??



Hmmm! Yet another Australian student who finds it easier to
post elementary questions on her homework assignment rather
than read the text book .....



Sent via Deja.com http://www.deja.com/
Before you buy.




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

* Re: Text Files
  2000-05-23  0:00 ` Cameron McShane
  2000-05-23  0:00   ` Marin D. Condic
@ 2000-05-23  0:00   ` Ted Dennison
  2000-05-23  0:00   ` tmoran
  2000-05-23  0:00   ` John English
  3 siblings, 0 replies; 14+ messages in thread
From: Ted Dennison @ 2000-05-23  0:00 UTC (permalink / raw)


In article <959088712.853876@hearts.q-net.net.au>,
  "Cameron McShane" <cazza@aceonline.com.au> wrote:

> When I try and get user input for the name of the string, ie
>
>     Text_io.get_line(Filename, Last);
>     Text_Io.Create(
>          File => In_Data,
>          Mode => Text_Io.Out_File,
>          Name => Filename(1..Last));
>
> it doesn't work
>
> Any ideas what i am doing wrong?

Can you give more detail than "it doesn't work"? Are you getting an
exception? If so, which one? If not, why do you think its not working?

--
T.E.D.

http://www.telepath.com/~dennison/Ted/TED.html


Sent via Deja.com http://www.deja.com/
Before you buy.




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

* Re: Text Files
  2000-05-23  0:00 ` Cameron McShane
  2000-05-23  0:00   ` Marin D. Condic
  2000-05-23  0:00   ` Ted Dennison
@ 2000-05-23  0:00   ` tmoran
  2000-05-23  0:00   ` John English
  3 siblings, 0 replies; 14+ messages in thread
From: tmoran @ 2000-05-23  0:00 UTC (permalink / raw)


>   Text_io.get_line(Filename, Last);
>   Text_Io.Create(
>        File => In_Data,
>        Mode => Text_Io.Out_File,
>        Name => Filename(1..Last));
>
>it doesn't work
  What does "it doesn't work" mean?  Your code looks good.  In what
way does it fail?




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

* Re: Text Files
  2000-05-23  0:00 Text Files Karlene
@ 2000-05-23  0:00 ` Marin D. Condic
  2000-05-23  0:00 ` Cameron McShane
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 14+ messages in thread
From: Marin D. Condic @ 2000-05-23  0:00 UTC (permalink / raw)
  To: Karlene

Karlene wrote:
> 
> How can you create a text file to be written to and read from (seperatley)
> in an ada program where the file name is inputed from the user??

That depends on what you mean by "separately". A text file cannot be
opened for read and write access simultaneously. You could first write
the file and close it, then reopen the file for read access and read
what you just wrote. As for getting the filename from the user, a
filename is just a string. So you read the string using Text_IO from the
standard input, perform whatever editing you need to do to the string,
then use it as a parameter in the Open or Create procedures.

You'll want to look at the Ada Reference Manual in the sections that
deal with Text_IO for more detail. If you don't have a copy, try:
http://www.adapower.com/ and look for the "Reference" button. On my web
page under the Ada Programming subpage, you will find a bunch of small
example programs I used to use in teaching an intro level Ada course.
(Look for GNAT_Examples.chop) There are several small programs there
which illustrate uses of Text_IO.

The procedure calls you will want to look at in Ada.Text_IO are in Annex
A: A.10.1

9		procedure Create (File : in out File_Type;
	                  Mode : in File_Mode := Out_File;
	                  Name : in String    := "";
	                  Form : in String    := "");
10		procedure Open   (File : in out File_Type;
	                  Mode : in File_Mode;
	                  Name : in String;
	                  Form : in String := "");

11		procedure Close  (File : in out File_Type);
	
Look over the explanations for these procedures and you'll likely be
able to figure it out.

MDC
-- 
======================================================================
Marin David Condic - Quadrus Corporation - http://www.quadruscorp.com/
Send Replies To: m c o n d i c @ q u a d r u s c o r p . c o m
Visit my web site at:  http://www.mcondic.com/

"I'd trade it all for just a little more"
    --  Charles Montgomery Burns, [4F10]
======================================================================




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

* Re: Text Files
  2000-05-23  0:00 Text Files Karlene
  2000-05-23  0:00 ` Marin D. Condic
@ 2000-05-23  0:00 ` Cameron McShane
  2000-05-23  0:00   ` Marin D. Condic
                     ` (3 more replies)
  2000-05-23  0:00 ` Ted Dennison
                   ` (2 subsequent siblings)
  4 siblings, 4 replies; 14+ messages in thread
From: Cameron McShane @ 2000-05-23  0:00 UTC (permalink / raw)


Hey

Im having a similar problem with this.

I have the program writing to a file etc, however only when using a direct
filename, ie

Text_Io.Create(
         File => In_Data,
         Mode => Text_Io.Out_File,
         Name => "c:\biff.txt");

This works beautifully.

When I try and get user input for the name of the string, ie

    Text_io.get_line(Filename, Last);
    Text_Io.Create(
         File => In_Data,
         Mode => Text_Io.Out_File,
         Name => Filename(1..Last));

it doesn't work

Any ideas what i am doing wrong?

Any help would be appreciated!

Cheers


Cameron


Karlene <kejohnso@student.ecu.edu.au> wrote in message
news:8gdguu$f9v$1@news.cowan.edu.au...
> How can you create a text file to be written to and read from (seperatley)
> in an ada program where the file name is inputed from the user??
>
>
>






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

* Re: Text Files
  2000-05-23  0:00 ` Cameron McShane
                     ` (2 preceding siblings ...)
  2000-05-23  0:00   ` tmoran
@ 2000-05-23  0:00   ` John English
  3 siblings, 0 replies; 14+ messages in thread
From: John English @ 2000-05-23  0:00 UTC (permalink / raw)


Cameron McShane wrote:
> I have the program writing to a file etc, however only when using a direct
> filename, ie
> 
> Text_Io.Create(
>          File => In_Data,
>          Mode => Text_Io.Out_File,
>          Name => "c:\biff.txt");
> 
> This works beautifully.
> 
> When I try and get user input for the name of the string, ie
> 
>     Text_io.get_line(Filename, Last);
>     Text_Io.Create(
>          File => In_Data,
>          Mode => Text_Io.Out_File,
>          Name => Filename(1..Last));
> 
> it doesn't work

When you say "it doesn't work" what exactly do you mean? Your code
looks fine (in isolation); do you get an exception of some sort
when you run it? If so, which one?

In particular, is Filename declared to be big enough to hold the
name you type in? Have you tried displaying the values of Last
and Filename(1..Last) to make sure they're what you expect?

-----------------------------------------------------------------
 John English              | mailto:je@brighton.ac.uk
 Senior Lecturer           | http://www.it.bton.ac.uk/staff/je
 Dept. of Computing        | ** NON-PROFIT CD FOR CS STUDENTS **
 University of Brighton    |    -- see http://burks.bton.ac.uk
-----------------------------------------------------------------




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

* Re: Text Files
  2000-05-23  0:00 ` Cameron McShane
@ 2000-05-23  0:00   ` Marin D. Condic
  2000-05-25  0:00     ` Cameron McShane
  2000-05-23  0:00   ` Ted Dennison
                     ` (2 subsequent siblings)
  3 siblings, 1 reply; 14+ messages in thread
From: Marin D. Condic @ 2000-05-23  0:00 UTC (permalink / raw)


Cameron McShane wrote:
> When I try and get user input for the name of the string, ie
> 
>     Text_io.get_line(Filename, Last);
>     Text_Io.Create(
>          File => In_Data,
>          Mode => Text_Io.Out_File,
>          Name => Filename(1..Last));
> 
> it doesn't work
> 
This looks like it ought to work presuming you have declared everything
properly. What compiler/version/OS are you using?

What you should try is echoing out the Filename string so you can see if
you are, in fact, reading everything you think you are reading. For
example, if the string variable is too short, you may not be getting the
full name. There is a chance that you may be getting extraneous
characters - perhaps left over from some previous input line that you
did not fully read. In any case, make sure that you are reading what you
*think* you are reading and that may help you solve the problem. If not,
strip down the program to *just* the declarations and code needed to
read the string & create the file. If this small sample doesn't work,
then post the code.

MDC
-- 
======================================================================
Marin David Condic - Quadrus Corporation - http://www.quadruscorp.com/
Send Replies To: m c o n d i c @ q u a d r u s c o r p . c o m
Visit my web site at:  http://www.mcondic.com/

"I'd trade it all for just a little more"
    --  Charles Montgomery Burns, [4F10]
======================================================================




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

* Re: Text Files
  2000-05-23  0:00 ` Robert Dewar
@ 2000-05-24  0:00   ` Marin D. Condic
  0 siblings, 0 replies; 14+ messages in thread
From: Marin D. Condic @ 2000-05-24  0:00 UTC (permalink / raw)


Robert Dewar wrote:
> Hmmm! Yet another Australian student who finds it easier to
> post elementary questions on her homework assignment rather
> than read the text book .....
> 
Well, elementary questions are at least mostly harmless. The ones that
disturb me are the "I need a program that implements <insert homework
assignment here> and I need it by tomorrow morning!" Getting basic
information from sources other than the book is one thing. Failure to do
the homework that makes you a skilled programmer is something else
alltogether.

MDC
-- 
======================================================================
Marin David Condic - Quadrus Corporation - http://www.quadruscorp.com/
Send Replies To: m c o n d i c @ q u a d r u s c o r p . c o m
Visit my web site at:  http://www.mcondic.com/

"I'd trade it all for just a little more"
    --  Charles Montgomery Burns, [4F10]
======================================================================




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

* Re: Text Files
  2000-05-23  0:00   ` Marin D. Condic
@ 2000-05-25  0:00     ` Cameron McShane
  2000-05-25  0:00       ` Jean-Pierre Rosen
  2000-05-26  0:00       ` Dale Stanbrough
  0 siblings, 2 replies; 14+ messages in thread
From: Cameron McShane @ 2000-05-25  0:00 UTC (permalink / raw)


Hey all

Thanks everyone for your comments and help

It seems that I needed a skip_line before the get_line.

    ie
    Text_io.skip_line;
    Text_io.get_line(Filename, Last);
    Text_Io.Create(
         File => In_Data,
         Mode => Text_Io.Out_File,
         Name => Filename(1..Last));

I was sure I had tried this already, but obviously I was mistaken.

Thanks again

Cameron


Marin D. Condic <mcondic-nospam@quadruscorp.com> wrote in message
news:392AF852.93E0EDBE@quadruscorp.com...
> Cameron McShane wrote:
> > When I try and get user input for the name of the string, ie
> >
> >     Text_io.get_line(Filename, Last);
> >     Text_Io.Create(
> >          File => In_Data,
> >          Mode => Text_Io.Out_File,
> >          Name => Filename(1..Last));
> >
> > it doesn't work
> >
> This looks like it ought to work presuming you have declared everything
> properly. What compiler/version/OS are you using?
>
> What you should try is echoing out the Filename string so you can see if
> you are, in fact, reading everything you think you are reading. For
> example, if the string variable is too short, you may not be getting the
> full name. There is a chance that you may be getting extraneous
> characters - perhaps left over from some previous input line that you
> did not fully read. In any case, make sure that you are reading what you
> *think* you are reading and that may help you solve the problem. If not,
> strip down the program to *just* the declarations and code needed to
> read the string & create the file. If this small sample doesn't work,
> then post the code.
>
> MDC
> --
> ======================================================================
> Marin David Condic - Quadrus Corporation - http://www.quadruscorp.com/
> Send Replies To: m c o n d i c @ q u a d r u s c o r p . c o m
> Visit my web site at:  http://www.mcondic.com/
>
> "I'd trade it all for just a little more"
>     --  Charles Montgomery Burns, [4F10]
> ======================================================================
>






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

* Re: Text Files
  2000-05-25  0:00     ` Cameron McShane
@ 2000-05-25  0:00       ` Jean-Pierre Rosen
  2000-05-26  0:00       ` Dale Stanbrough
  1 sibling, 0 replies; 14+ messages in thread
From: Jean-Pierre Rosen @ 2000-05-25  0:00 UTC (permalink / raw)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1091 bytes --]


Cameron McShane <cazza@aceonline.com.au> a �crit dans le message : 959260098.454638@hearts.q-net.net.au...
> Hey all
>
> Thanks everyone for your comments and help
>
> It seems that I needed a skip_line before the get_line.
>
>     ie
>     Text_io.skip_line;
>     Text_io.get_line(Filename, Last);
>     Text_Io.Create(
>          File => In_Data,
>          Mode => Text_Io.Out_File,
>          Name => Filename(1..Last));
>
> I was sure I had tried this already, but obviously I was mistaken.
>
Wouldn't you, by any chance, be reading an integer value before ? If you do:
-- assuming proper instantiation of Integer_IO
Get (I);
Get_Line (File_Name, Last);

the first Get will leave you in front of the End_Of_Line, and the Get_Line will read an empty string.
In this case, you don't really need a Skip_Line *before the Get_Line*. What you really need is a Skip_Line *after the Get*. Not
exactly the same thing...

--
---------------------------------------------------------
           J-P. Rosen (Rosen.Adalog@wanadoo.fr)
Visit Adalog's web site at http://pro.wanadoo.fr/adalog






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

* Re: Text Files
  2000-05-25  0:00     ` Cameron McShane
  2000-05-25  0:00       ` Jean-Pierre Rosen
@ 2000-05-26  0:00       ` Dale Stanbrough
  1 sibling, 0 replies; 14+ messages in thread
From: Dale Stanbrough @ 2000-05-26  0:00 UTC (permalink / raw)


Cameron McShane wrote:

> Hey all
> 
> Thanks everyone for your comments and help
> 
> It seems that I needed a skip_line before the get_line.
> 
>     ie
>     Text_io.skip_line;
>     Text_io.get_line(Filename, Last);
>     Text_Io.Create(
>          File => In_Data,
>          Mode => Text_Io.Out_File,
>          Name => Filename(1..Last));
> 
> I was sure I had tried this already, but obviously I was mistaken.



I would suggest that you download my (actually the FSF's!) interactive
text_io simulator that lets you examine the effect of various input 
routines.
It's at...

     www.cs.rmit.edu.au/~dale/software/index.html


look for Io_View. I would certainly recommend that your lecturer installs
it on your computers for everyone to use.


Dale




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

end of thread, other threads:[~2000-05-26  0:00 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-05-23  0:00 Text Files Karlene
2000-05-23  0:00 ` Marin D. Condic
2000-05-23  0:00 ` Cameron McShane
2000-05-23  0:00   ` Marin D. Condic
2000-05-25  0:00     ` Cameron McShane
2000-05-25  0:00       ` Jean-Pierre Rosen
2000-05-26  0:00       ` Dale Stanbrough
2000-05-23  0:00   ` Ted Dennison
2000-05-23  0:00   ` tmoran
2000-05-23  0:00   ` John English
2000-05-23  0:00 ` Ted Dennison
2000-05-23  0:00 ` David Freshwater
2000-05-23  0:00 ` Robert Dewar
2000-05-24  0:00   ` Marin D. Condic

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