Re: I think it works?
- Posted by Irv Mullins <irv at ELLIJAY.COM> Jul 23, 1999
- 457 views
On Fri, 23 Jul 1999, you wrote: > I think that it works but I'm not sure. It runs without any error > message, but I can't find the output anywhere. I search for the out > file but none exists. Does Euphoria put the output in the same > directory the input file resides? Hi Bryan: Euphoria will put the output file in the directory you are in when the program is run (not necessarily the directory where the input file is) If you are processing a tlat text file, then you want to do the following: --- set COPY = 0 start of loop read each line. if end of file then quit If the line starts with ST, then set COPY = 1 elsif the line starts with SE then set COPY = 0 if COPY = 1 then write the line to the output file back to start of loop. --- Now, first of all, you have to determine whether the line contains ONLY ST (or SE), or whether it may have other stuff following: i.e. ST SoMe other TExt. If other text sometimes follows, you can look at only the first two characters of each line. You also have to determine (by looking at the file) whether the ST / SE always are the first two characters in the lines, not, for example: ,<space><space>ST. If there are sometimes spaces, then you have to remove spaces before you can compare. The code above can be written: object line integer fn,fo, -- file in file out copy -- flag fn = open("Input.txt","r") fo = open("output.txt","w") copy = 0 while 1 do -- loop forever line = gets(fn) -- read a line if atom(line) then exit -- bail out when end of file is reached end if if equal ( line[1..2] , "ST" ) then copy = 1 -- look for ST and set flag when elsif equal ( line[1..2] , "SE" ) then copy = 0 end if if copy = 1 then puts(fo, line) -- write the line to the output file end if end while close(fn) close(fo) Hope that helps, Irv Mullins