PLAIN_TEXT_FILE

This is a discussion on PLAIN_TEXT_FILE within the Eiffel forums in Programming Languages category; I want to change a file consisting of customer records. Every line is finished by a return; so I think the file should be formated properly. I read every line one after the other, rewriting the lines without the first seven characters. The first line is read correctly, but remains unchanged. Furthermore, file.next_line does not move to the next line but to a arbitrary position. What is wrong with the code? Thanks for any help. class APPLICATION create make feature -- Initialization make is -- Run application. local file: PLAIN_TEXT_FILE text_line: STRING do create file.make_open_read_write ("kunden.tab") if file.exists then if ...

Go Back   Application Development Forum > Programming Languages > Eiffel

Object Mix

Register FAQ Calendar Search Today's Posts Mark Forums Read
  #1  
Old 11-03-2007, 10:21 AM
=?ISO-8859-1?Q?Roman_T=F6ngi?=
Guest
 
Default PLAIN_TEXT_FILE

I want to change a file consisting of customer records.
Every line is finished by a return; so I think the file
should be formated properly.

I read every line one after the other, rewriting the lines
without the first seven characters.

The first line is read correctly, but remains unchanged.
Furthermore, file.next_line does not move to the next line but
to a arbitrary position.

What is wrong with the code? Thanks for any help.



class
APPLICATION
create
make
feature -- Initialization
make is
-- Run application.
local
file: PLAIN_TEXT_FILE
text_line: STRING
do
create file.make_open_read_write ("kunden.tab")
if file.exists then
if file.readable and file.writable then
from
file.start
until
file.end_of_file
loop
file.read_line
text_line := file.last_string.substring (7, file.last_string.count)
file.put_string (text_line)
file.next_line
end
end
file.close
end
end
end -- class APPLICATION
Reply With Quote
  #2  
Old 11-03-2007, 02:08 PM
Jean RUPPERT
Guest
 
Default Re: PLAIN_TEXT_FILE

Hello Roman,

I only have smarteiffel, and I cannot
testy your code, so I don't know what is
wrong with it. Maybe reading and writing
at the same time to a file causes some problems.
Maybe you read again the line you just have written
I would try this out, even though it is not very
elegant. If it does not help you please tell me

Yours

Jean

class
APPLICATION
create
make
feature -- Initialization
make is
-- Run application.
local
input_file: PLAIN_TEXT_FILE
output_file: PLAIN_TEXT_FILE
text_line: STRING
do
create input_file.make_open_read ("kunden.tab")
create output_file.make_open_write ("kunden_neu.tab")
if input_file.exists then
if input_file.readable and output_file.writable then
from
input_file.start
until
input_file.end_of_file
loop
input_file.read_line
text_line := input_file.last_string.substring

(7, file.last_string.count)
output_file.put_string (text_line)
input_file.next_line
end
end
output_file.close
input_file.close
end
end
end -- class APPLICATION


Roman Töngi a écrit :
> I want to change a file consisting of customer records.
> Every line is finished by a return; so I think the file
> should be formated properly.
>
> I read every line one after the other, rewriting the lines
> without the first seven characters.
>
> The first line is read correctly, but remains unchanged.
> Furthermore, file.next_line does not move to the next line but
> to a arbitrary position.
>
> What is wrong with the code? Thanks for any help.
>
>
>
> class
> APPLICATION
> create
> make
> feature -- Initialization
> make is
> -- Run application.
> local
> file: PLAIN_TEXT_FILE
> text_line: STRING
> do
> create file.make_open_read_write ("kunden.tab")
> if file.exists then
> if file.readable and file.writable then
> from
> file.start
> until
> file.end_of_file
> loop
> file.read_line
> text_line := file.last_string.substring (7,
> file.last_string.count)
> file.put_string (text_line)
> file.next_line
> end
> end
> file.close
> end
> end
> end -- class APPLICATION

Reply With Quote
  #3  
Old 11-03-2007, 03:37 PM
=?ISO-8859-1?Q?Roman_T=F6ngi?=
Guest
 
Default Re: PLAIN_TEXT_FILE

next_line is not necessary. read_line already moves cursor to next position.

Jean RUPPERT wrote:
> Hello Roman,
>
> I only have smarteiffel, and I cannot
> testy your code, so I don't know what is
> wrong with it. Maybe reading and writing
> at the same time to a file causes some problems.
> Maybe you read again the line you just have written
> I would try this out, even though it is not very
> elegant. If it does not help you please tell me
>
> Yours
>
> Jean
>
> class
> APPLICATION
> create
> make
> feature -- Initialization
> make is
> -- Run application.
> local
> input_file: PLAIN_TEXT_FILE
> output_file: PLAIN_TEXT_FILE
> text_line: STRING
> do
> create input_file.make_open_read ("kunden.tab")
> create output_file.make_open_write ("kunden_neu.tab")
> if input_file.exists then
> if input_file.readable and output_file.writable then
> from
> input_file.start
> until
> input_file.end_of_file
> loop
> input_file.read_line
> text_line := input_file.last_string.substring
> (7, file.last_string.count)
> output_file.put_string (text_line)
> input_file.next_line
> end
> end
> output_file.close
> input_file.close
> end
> end
> end -- class APPLICATION
>
>
> Roman Töngi a écrit :
>> I want to change a file consisting of customer records.
>> Every line is finished by a return; so I think the file
>> should be formated properly.
>>
>> I read every line one after the other, rewriting the lines
>> without the first seven characters.
>>
>> The first line is read correctly, but remains unchanged.
>> Furthermore, file.next_line does not move to the next line but
>> to a arbitrary position.
>>
>> What is wrong with the code? Thanks for any help.
>>
>>
>>
>> class
>> APPLICATION
>> create
>> make
>> feature -- Initialization
>> make is
>> -- Run application.
>> local
>> file: PLAIN_TEXT_FILE
>> text_line: STRING
>> do
>> create file.make_open_read_write ("kunden.tab")
>> if file.exists then
>> if file.readable and file.writable then
>> from
>> file.start
>> until
>> file.end_of_file
>> loop
>> file.read_line
>> text_line := file.last_string.substring (7,
>> file.last_string.count)
>> file.put_string (text_line)
>> file.next_line
>> end
>> end
>> file.close
>> end
>> end
>> end -- class APPLICATION

Reply With Quote
  #4  
Old 11-07-2007, 03:35 AM
Ulrich Windl
Guest
 
Default Re: PLAIN_TEXT_FILE

Roman Töngi <roman.toengi@hispeed.ch> writes:

> I want to change a file consisting of customer records.
> Every line is finished by a return; so I think the file
> should be formated properly.
>
> I read every line one after the other, rewriting the lines
> without the first seven characters.


Actually, I'd use one of the existing UNIX utilities like "cut -c7-" or
"sed -e 's/^.......//'".

>
> The first line is read correctly, but remains unchanged.
> Furthermore, file.next_line does not move to the next line but
> to a arbitrary position.
>
> What is wrong with the code? Thanks for any help.
>
>
>
> class
> APPLICATION
> create
> make
> feature -- Initialization
> make is
> -- Run application.
> local
> file: PLAIN_TEXT_FILE
> text_line: STRING
> do
> create file.make_open_read_write ("kunden.tab")
> if file.exists then
> if file.readable and file.writable then
> from
> file.start
> until
> file.end_of_file
> loop
> file.read_line
> text_line := file.last_string.substring (7, file.last_string.count)
> file.put_string (text_line)
> file.next_line
> end
> end
> file.close
> end
> end
> end -- class APPLICATION

Reply With Quote
  #5  
Old 11-07-2007, 04:43 AM
Bernd Schoeller
Guest
 
Default Re: PLAIN_TEXT_FILE

On Wed, 07 Nov 2007 09:35:48 +0100, Ulrich Windl
<Ulrich.Windl@RZ.Uni-Regensburg.DE> wrote:

> Roman Töngi <roman.toengi@hispeed.ch> writes:
>
>> I want to change a file consisting of customer records.
>> Every line is finished by a return; so I think the file
>> should be formated properly.
>>
>> I read every line one after the other, rewriting the lines
>> without the first seven characters.

>
> Actually, I'd use one of the existing UNIX utilities like "cut -c7-" or
> "sed -e 's/^.......//'".


From Roman's Mail Header:
> User-Agent: Thunderbird 2.0.0.4 (Windows/20070604)


I think there is a need to get into the Unix way of thinking about
problems. Using Thunderbird was a good start, installing CYGWIN might be
the next step :-)

While it is nice to consider "doing everything in Eiffel", choosing the
right tools for the right job seems appropriate.

Bernd

PS: Do not take this comment too seriously :-)
Reply With Quote
Reply


Thread Tools
Display Modes


All times are GMT -5. The time now is 05:43 AM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
vB Ad Management by =RedTyger=

In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.