0984

File Handling

Programming · 4 question types

Exam Frequency Analysis

Past paper frequency (2018 to 2024)

This topic accounts for approximately 3% of your exam marks.

stable
Rare
Stable3%

OPENFILE, READFILE, WRITEFILE, CLOSEFILE pseudocode operations appear occasionally.

Common mistakes that lose marks (and lose data in real programs):

  • Opening a in WRITE mode when you meant to keep its existing data. WRITE mode overwrites the file, destroying all existing contents.
  • Forgetting CLOSEFILE. Buffered data may not reach the disk; the file may be incomplete or corrupt.
  • Reading past the end of the file without checking for it. There is no EOF function in CIE pseudocode, so always test the line you have just read against a sentinel value and stop the loop with a Boolean flag.
  • Opening a file that does not exist in READ mode. Causes a runtime error; check it exists first if necessary.
  • Mixing modes. A single OPENFILE opens for one specific mode. To switch between reading and writing, close and reopen the file.
  • Forgetting to handle blank lines when reading. An empty line is often used as the end-of-file sentinel in the CIE pseudocode pattern, so be careful with files that genuinely contain blank lines in the middle.
  • Always make a backup of important text files before writing to them. A program with a bug can wipe out hours of work in milliseconds.