* File IO problem
@ 2002-12-06 6:27 prashna
2002-12-06 7:14 ` Martin Dowie
2002-12-06 17:13 ` File IO problem Jeffrey Carter
0 siblings, 2 replies; 5+ messages in thread
From: prashna @ 2002-12-06 6:27 UTC (permalink / raw)
Hi all,
Pls have a look at the following code
with text_Io;
use text_io;
Procedure FILE_IO_DEMO is
FILE_I, FILE_O : FILE_TYPE;
S : STRING(1..80);
Len : Integer;
begin
open (FILE_I, IN_FILE,"junk.txt");
create(FILE_O, OUT_FILE, "output.txt");
while END_OF_FILE(FILE_I) loop
GET_LINE(FILE_I, S, Len);
PUT_LINE(S(1..LEN));
PUT_LINE(FILE_O,S(1..Len));
end loop;
end;
The contents of the file junk.txt is
lafeosbv
qfowep p4gowb
hfwevwpbv
The program is creating output.txt but it contents are nil.
Pls let me know if I am doing wrong.Any help will be appriciated.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: File IO problem
2002-12-06 6:27 File IO problem prashna
@ 2002-12-06 7:14 ` Martin Dowie
2002-12-06 11:50 ` File IO problem - silly mistake :o( prashna
2002-12-06 17:13 ` File IO problem Jeffrey Carter
1 sibling, 1 reply; 5+ messages in thread
From: Martin Dowie @ 2002-12-06 7:14 UTC (permalink / raw)
"prashna" <vashwath@rediffmail.com> wrote in message
news:d40d7104.0212052227.3aaa570a@posting.google.com...
> while END_OF_FILE(FILE_I) loop
You'll probably want a second look at this line.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: File IO problem - silly mistake :o(
2002-12-06 7:14 ` Martin Dowie
@ 2002-12-06 11:50 ` prashna
2002-12-07 13:33 ` SteveD
0 siblings, 1 reply; 5+ messages in thread
From: prashna @ 2002-12-06 11:50 UTC (permalink / raw)
"Martin Dowie" <martin.dowie@no.spam.btopenworld.com> wrote in message news:<aspio0$dik$1@knossos.btinternet.com>...
> "prashna" <vashwath@rediffmail.com> wrote in message
> news:d40d7104.0212052227.3aaa570a@posting.google.com...
> > while END_OF_FILE(FILE_I) loop
>
> You'll probably want a second look at this line.
Thank's Martin, I corrected it to "not END_OF_FILE(FILE_I)" now it is working fine.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: File IO problem
2002-12-06 6:27 File IO problem prashna
2002-12-06 7:14 ` Martin Dowie
@ 2002-12-06 17:13 ` Jeffrey Carter
1 sibling, 0 replies; 5+ messages in thread
From: Jeffrey Carter @ 2002-12-06 17:13 UTC (permalink / raw)
prashna wrote:
> Hi all,
> Pls have a look at the following code
>
> with text_Io;
> use text_io;
> Procedure FILE_IO_DEMO is
> FILE_I, FILE_O : FILE_TYPE;
> S : STRING(1..80);
> Len : Integer;
> begin
> open (FILE_I, IN_FILE,"junk.txt");
> create(FILE_O, OUT_FILE, "output.txt");
> while END_OF_FILE(FILE_I) loop
> GET_LINE(FILE_I, S, Len);
> PUT_LINE(S(1..LEN));
> PUT_LINE(FILE_O,S(1..Len));
> end loop;
> end;
>
> The contents of the file junk.txt is
> lafeosbv
> qfowep p4gowb
> hfwevwpbv
>
> The program is creating output.txt but it contents are nil.
This is an example of why, in 1980, Ichbiah, Barnes, & Firth recommended
not using while loops. It is natural to think about the exit condition
for a loop, but a while loop requires its opposite, the continuation
condition.
Had this been written with an exit:
loop
exit when End_Of_File (File_I);
there would not have been a problem.
--
Jeff Carter
"From this day on, the official language of San Marcos will be Swedish."
Bananas
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: File IO problem - silly mistake :o(
2002-12-06 11:50 ` File IO problem - silly mistake :o( prashna
@ 2002-12-07 13:33 ` SteveD
0 siblings, 0 replies; 5+ messages in thread
From: SteveD @ 2002-12-07 13:33 UTC (permalink / raw)
"prashna" <vashwath@rediffmail.com> wrote in message
news:d40d7104.0212060350.7071cf8a@posting.google.com...
> "Martin Dowie" <martin.dowie@no.spam.btopenworld.com> wrote in message
news:<aspio0$dik$1@knossos.btinternet.com>...
> > "prashna" <vashwath@rediffmail.com> wrote in message
> > news:d40d7104.0212052227.3aaa570a@posting.google.com...
> > > while END_OF_FILE(FILE_I) loop
> >
> > You'll probably want a second look at this line.
>
>
> Thank's Martin, I corrected it to "not END_OF_FILE(FILE_I)" now it is
working fine.
I would also suggest adding:
with Ada.Exceptions;
use Ada.Exceptions;
To the start of the file, and
exception
when REASON: others =>
Put_Line( "EXCEPTION NAME: " & Exception_Name( REASON ) );
Put_Line( "EXCEPTION MESSAGE: " & Exception_Message( REASON ) );
Put_Line( "EXCEPTION INFORMATION: " & Exception_Information( REASON ) );
immediately before the last "end".
If you remove the last new line from your source file and re-run the program
with these additions you'll see why I make this suggestion.
SteveD
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2002-12-07 13:33 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-12-06 6:27 File IO problem prashna
2002-12-06 7:14 ` Martin Dowie
2002-12-06 11:50 ` File IO problem - silly mistake :o( prashna
2002-12-07 13:33 ` SteveD
2002-12-06 17:13 ` File IO problem Jeffrey Carter
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox