1. Writing Strings to Text Files

Dear Euphorians,

I was working on a program a while ago that
would generate random names from a list of
words and adjectives. Everything was going
A-OK, until I got the bright idea to write
the results of this random generation to a
simple text file. Since then, I've been looking
for a way to write the contents of a string
to a text file. [I keep on getting error 3]
If someone could suggest a solution, it would
be much appreciated. (this could also be used
for making high score files, couldn't it?)

Thanks,


Chris Cox
cox.family at sk.sympatico.ca

new topic     » topic index » view message » categorize

2. Re: Writing Strings to Text Files

>I was working on a program a while ago that
>would generate random names from a list of
>words and adjectives. Everything was going
>A-OK, until I got the bright idea to write
>the results of this random generation to a
>simple text file. Since then, I've been looking
>for a way to write the contents of a string
>to a text file. [I keep on getting error 3]
>If someone could suggest a solution, it would
>be much appreciated. (this could also be used
>for making high score files, couldn't it?)

Here is testio.ex which copies itself to mycopy.ex
Cut & paste and save as testio.ex .. run it .. and it will 1) display all
code 2) copy all its own code to mycopy.ex

I think this show what you want to know ?
Anyways, good luck.

Ralf

--[testio.ex]
integer fh_write, fh_read

fh_read = open ("testio.ex", "r")
if not fh_read then
    puts (1, "Cannot read from testio.ex .. does the file exist at this
location ?\n")
    abort(1)
end if

fh_write = open ("mycopy.ex", "w")
if not fh_write then
    puts (1,"Cannot write to disk!\n")
    abort(1)
end if

-- Will contain the line currently being 'copied'
object line

-- read in line
line = gets (fh_read)

-- gets () will return -1 at the end of the file which is not a sequence
anymore
while sequence(line) do

    -- echo line to the screen
    puts (1, line)

    -- write line to mycopy.ex
    puts (fh_write, line)

    -- read in new line
    line = gets(fh_read)

end while

-- end message
puts (1, "All done!\n")

-- Closing file handles (at the end of execution Euphoria will do this for
you)
close (fh_read)
close (fh_write)

--[End of testio.ex]

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu