IonicWind Software

IWBasic => General Questions => Topic started by: oneplace2u on January 17, 2010, 08:18:56 AM

Title: Copying lines of a file over to another file
Post by: oneplace2u on January 17, 2010, 08:18:56 AM
I have a file that I am trying to copy over to another file, put I am having a problem with it, it will not copy a whole line over to the other file.
It will copy 3/4 of the line and then drop down and add the net line to it., But will copy the next line ok and will do this all the way down the file.

The reason I am copying these files over is to stop doing so much typing.

The file that I am copy from has two lines all the way down the file that are the main lines.
What I am trying to do is copy the first line twice and then adding the second line.

Here is my script:

openfile(myfile,"c:\\work\\cutlery-fix.txt", "W")
openfile(discfile,"c:\\work\\cutlery.txt", "R")
do
read discfile,bh[a]

a = a + 1
until eof(discfile)
closefile discfile
b = 1
label round
if b = a then Goto exit

write myfile, bh[b]
write myfile, bh[b]
write myfile, bh[b + 1]
b = b + 2
goto round


Here is the first two lines of the files, it basicly the same all the way down

Diamond CutÂÃ,® Supreme 2pc Kitchen Shear Set  Set includes poultry shears with notch in blade for cutting chicken bones, cord and small wire and all-purpose shears great for frozen food bags, pizza, paper, and anything you need heavy-duty shears
1.80
This will only copy to the "all purpose
on both lines and will add the "1.80 on the next line like this:

Diamond CutÂÃ,® Supreme 2pc Kitchen Shear Set  Set includes poultry shears with notch in blade for cutting chicken bones, cord and small wire and all-purpose1.80
Diamond CutÂÃ,® Supreme 2pc Kitchen Shear Set  Set includes poultry shears with notch in blade for cutting chicken bones, cord and small wire and all-purpose1.80
1.80
Title: Re: Copying lines of a file over to another file
Post by: LarryMc on January 17, 2010, 09:28:19 AM
show us how you defined your array bh

Larry
Title: Re: Copying lines of a file over to another file
Post by: LarryMc on January 17, 2010, 09:43:29 AM
I believe you created your array as a STRING instead of an ISTRING.
A STRING variable will only hold 255 characters.

See this to see how to define and use an ISTRING array.
http://www.ionicwind.com/forums/index.php/topic,1650.msg15239.html#msg15239

Larry
Title: Re: Copying lines of a file over to another file
Post by: billhsln on January 17, 2010, 10:46:08 AM
Give this code a try, if I understand what you are trying to do and 1000 characters is enough length for you maximum line, then this should do what you are trying to accomplish.

openfile(myfile,"c:\\work\\cutlery-fix.txt", "W")
openfile(discfile,"c:\\work\\cutlery.txt", "R")
def discin[1000]:istring
def a:int
'  old programmers trick: start a at 0, then a = 1 - 0 = 1, or a = 1 - 1 = 0
'   or if a is on (1), turn off (0), if off (0) then turn on (1)
'     a = 1 - a
a = 0
do
read discfile, discin
write myfile, discin
if a = 0 then write myfile, discin
a = 1 - a
until eof(discfile)
closefile discfile
closefile myfile
end


Bill