Common mistakes in file handling pseudocode
A mistake such as using the wrong mode, missing OPENFILE or CLOSEFILE, using different file names, or opening a file FOR WRITE and wiping its old data.
Understanding Common mistakes in file handling pseudocode in IGCSE Computer Science Paper 2
What it does: This code opens the file first and only then reads from it, which avoids the error of using a file before OPENFILE. CLOSEFILE after the last WRITEFILE makes sure the data is saved, avoiding the mistake of forgetting CLOSEFILE. READFILE needs the file to be opened FOR READ. A file opened FOR WRITE can only have data written to it, and opening it FOR WRITE also wipes its old data. The same file name must be used in OPENFILE, READFILE and CLOSEFILE, so READFILE should use "marks.txt".
Common mistakes: The program reads from the file, so it must be opened FOR READ. Opening it FOR WRITE would wipe the old data, and READFILE cannot be used on a file opened for WRITE. The file identifier in CLOSEFILE must match the one used in OPENFILE. "log.text" is a different file, so log.txt is never closed. It should be CLOSEFILE "log.txt".
Free printable worksheet with full answer key — or add this module to a class and your students practise it interactively.
This module's key terms are also in a printable crossword (Modules 500–522) and word search (Modules 500–538).
Take this worksheet further — free with Cloodit
Each concept is reinforced from every angle — learned, then applied, then tested.
Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.
Over 100 of them, across seven natural biomes.
Turns their work into revision material ready for Flash Cards and Exam study.
Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.
Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.
Quick Questions
Match the Pairs
Key Term
file handling errorFill in the Blanks
Spot the Error
Student with a class code? Join your class →