WRITEFILE: writing a single item of data
Writes the value stored in a variable into an open file. Give the file name, a comma, then the variable. The file must already be open in WRITE mode.
Understanding WRITEFILE: writing a single item of data in IGCSE Computer Science Paper 2
What it does: WRITEFILE only works on a file that is already open in WRITE mode, so OPENFILE ... FOR WRITE comes first. The order is file name string, comma, variable. Here "Marks.txt" is the file identifier and Mark is the variable. WRITEFILE writes the value stored in the variable, not the variable's name. The two items must be separated by a comma: WRITEFILE "Scores.txt", Score.
Common mistakes: WRITEFILE only works on a file opened in WRITE mode. Line 2 opens the file FOR READ, so it should be OPENFILE "Scores.txt" FOR WRITE. The file identifier is a string, so the file name must be in quotes. It should be OPENFILE "Names.txt" FOR WRITE.
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 489–499) and word search (Modules 479–499).
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
WRITEFILE "Scores.txt", ScoreFill in the Blanks
Spot the Error
Student with a class code? Join your class →