WriteArray()
Summary
Writes the elements of an array to a text file.
Syntax
WriteArray(file file_ptr, array a)
| Argument | Contents |
|---|---|
| file_ptr | A file handle |
| a | An array of strings and numbers |
Notes
-
All elements of the array are written as strings.
-
Each element of the array is written to a separate line in the file.
-
The file must be opened in write mode.
-
Array elements that are not numeric or strings are ignored, so WriteArray() does not handle sub- arrays.
-
Use SaveArray() to save an array in a binary format that can be read by LoadArray().
Example
list = {"Eric", "Mary", "Aaron", 275, "Howard"}
ptr = OpenFile("listfile.txt", "w")
WriteArray(ptr, list)
CloseFile(ptr)
Error Codes
| Error Type | Meaning |
|---|---|
| Error | File is not open, is open in read-only mode, or is a binary file |
See Also
| Function | Summary |
|---|---|
| OpenFile() | Opens a text or binary file on disk |
| ReadArray() | Reads a text file into an array of strings |
| ReadSizedArray() | Reads a group of strings from a file |
| SaveArray() | Saves an array to a file |
| WriteArraySeparated() | Writes the elements of an array to a file, separated by a delimiter |