I need help! (again :>)

new topic     » topic index » view thread      » older message » newer message

I'm writing a program to read in a file and change certain pieces of
text to something else. For instance in the file I would change all
instances of '1' to '2'. However when I try to "find" the text I want
to change in my sample file it returns 0. Can anyone help?

<CODE>

include get.e
include file.e

without warning
with trace

sequence cmd, file, x
atom fn, n, m
object tmp, line

x = {}

cmd = command_line()
if length(cmd) < 3 then
        puts(1, "Wrong options. Correct format is:\n")
        puts(1, "filter <input> <output>\n")
        puts(1, "<input> - file to filter\n")
        puts(1, "<output> - name of new file\n")
        abort(1)
end if

tmp = dir(cmd[3])

if atom(tmp) then
        puts(1, "File not found!\n")
        abort(1)
end if

fn = open(cmd[3], "r")
file = {}
while 1 do
        line = gets(fn)
        if atom(line) then
                exit
        end if
        file = append(file, line)
end while
close(fn)

trace(1)
? file[1]
for i = 1 to length(file) do
        n = find("1", file[i])
                if n != -1 then
                        m = i - 1
                        x = file[i][1..m]
                        x = x & "2"
                        m = i + 1
                        x = x & file[i][m..length(file[i])]
                        file[i] = x
                end if
end for
fn = open(cmd[4], "w")
for i = 1 to length(file) do
        printf(fn, "%s", file[i])
end for
close(fn)
trace(0)

</CODE>

~~>Joseph Martin
~~>E-mail:  joe at cyber-wizard.com
~~>URL: http://users.exis.net/~jam/

new topic     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu