File and array

Loading a file into an array

A file may be loaded into an array with a single function:

array a
a.load("filename")


Each line of the file becomes an element of the array. The end of line codes are not removed (codes 10 or 13 according to the operating system). In the chapter about "scan", this control structure will be studied in depth. For the moment, without to try to understand the syntax, know that you can view the content of a file with only two statements:

a.load("fcat.sol")
scan a print a[]

Saving an array into a file

An array may be saved as a whole with the "store" method.
a.store("filename")

End of line code must be added to each line.

End of line codes

Just for information, end of line code inside a file are:
- under Windows: 10 followed by 13
- under Unix: 13
- under MacIntosh: 10
But we have just to add the text "\n", that will be converted automatically into the code of the environment.

Example array a
a.load("fcat.sol")
scan a let a[] = a[].toText().rTrim()    `removing codes
a.display()

 Exercises

 

1) Here is an array:
array a = (1, 2 , 3)
Save it into the test.txt file.
Then, read and display this file.

Answer