There are two types of files for storing data in nuBASIC – namely, text files and binary files.
Files opened both for text and binary access may be read or written, beginning at any location within the file.
The Open statement is used to open files - that is, it makes files available so that you can read or write to them.
This statement is present in many BASIC dialects, and in nuBASIC is implemented with the most commonly accepted syntax.
nuBASIC provides also a second statement to open files FOpen.
This statement, as the name suggests, comes from C stdio fopen API.
The Print#(or Write#) instruction writes data to a file - the data is written to the file whose number follows "#".
It works like Print, except that the information is sent to the file instead of printed to the screen.
Of course a file must be opened before anything can be written to it - so always an Open/FOpen command must precede a Print # statement.
Often when reading data from a file a program does not know beforehand the length of the file. If the reading is done from within a loop, there must be a way to stop the loop when all the data is read - otherwise, nuBASIC fails when asked to read more data after the end of the file has been reached.
For this purpose nuBASIC employs a function Eof(filenumber%), that checks whether the last reading of the file used up all the data in the file.
The function Eof(filenumber%) checks the end-of-file indicator. If no error has occurred on filenumber%, Eof returns 1 If end- is reached, else it returns 0.
If filenumber% is invalid, Eof sets errno to 22 and returns -1.
If no error has occurred on file, FError returns 0.
If filenum is invalid, FError sets errno to 22 and returns -1.
Otherwise, it returns a nonzero positive value.