Another doubt about reading/writing files...

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

3/4/97 17:57, you wrote:

>Poster:       Ricardo Niederberger Cabral <rnc at INFOLINK.COM.BR>
>Subject:      Another doubt about reading/writing files...
>--------------------------------------------------------------------------
-----

>        Here I am with another doubt:

>I would like to save a 2D array (a sequence of sequences) that I
initialized
>like this:
>        MapVar = repeat(repeat({0, 0}, 100), 100)
>in a data file (could be binary or whatever...) so I can read it later.
How
>can I do it using Euphoria ?

>Thanks,

>---
>Ricardo Niederberger Cabral

Hi Ricardo,

The simplest way to write and read a sequence is the following:

include file.e
---------------------------------------------------------------------------
------------
procedure save_data()
integer file
    file = open("MapVar.dat", "w") -- open for writing
    if file = -1 then
        puts(1, "Unable to open file!")
        abort(1)
    else
        print(file, MapVar)     -- 'print' is the easiest form of writing
to files
        close(file)
    end if
end procedure   -- save_data
---------------------------------------------------------------------------
------------
procedure load_data()
integer file
object input
    file = open("MapVar.dat", "r")      -- open for reading
    if file = -1 then
        puts(1, "Unable to open file!")
        abort(1)
    else
        input = get(file)               -- 'get' is the opposite of print
        if input[1] = GET_SUCCESS then  -- succesfully loaded?
            MapVar = input[2]           -- put it in your sequence
        end if
        close(file)
    end if
end procedure   -- load_data
---------------------------------------------------------------------------
------------

Hope this helps

---------------------------------------------------------------------------
------------
Ad Rienks       AdRienks at compuserve.com

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

Search



Quick Links

User menu

Not signed in.

Misc Menu