9618 · 10.3
Files flashcards
Revision flashcards for Cambridge 9618 Files (syllabus 10.3). Flip, recall, then mark a real past-paper question.
Card
What is a text file?
A type of file that stores data as a sequence of characters, organised into lines. It can be opened and read by a human using a simple text editor.
Card
What is a 'record' in the context of a file?
A collection of related data items, often stored on a single line in a text file. For example, a student's ID, name, and grade could form one record.
Card
What is a 'field' in the context of a file?
A single data item within a record. For example, in the record '123,John Smith,A', the name 'John Smith' is a field.
Card
What is a 'file handle'?
A reference or pointer to a file that is returned when you open it. In Cambridge pseudocode, the filename itself is used as the handle (e.g., `READFILE "MyData.txt", ...`).
Card
What does opening a file in `READ` mode do?
It opens an existing file and allows the program to read data from it, starting from the beginning. You cannot write to a file in READ mode.
Card
What does opening a file in `WRITE` mode do?
It creates a new, empty file with the given name. If a file with that name already exists, its contents are permanently deleted and overwritten.
Card
What does opening a file in `APPEND` mode do?
It opens an existing file and allows the program to add new data to the very end of it. If the file does not exist, it is created.
Card
What is the `EOF()` function used for?
`EOF(<filename>)` stands for End-Of-File. It is a boolean function that returns TRUE when the program has attempted to read past the last piece of data in a file. It's used to control loops for reading files.
Card
What is a common mistake when using `WRITE` mode?
Accidentally using `WRITE` mode when you meant to use `APPEND`. This will erase all existing data in the file without warning.
Card
Why is `CLOSEFILE` essential, especially after writing?
Data written to a file may be held in a temporary buffer in memory. `CLOSEFILE` ensures this buffer is flushed (written) to the disk, saving the changes permanently and releasing the file.