Another doubt about reading/writing files...
- Posted by Ad Rienks <Ad_Rienks at COMPUSERVE.COM> Apr 03, 1997
- 1017 views
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