Skip to content

9618 · 10.3

Files — common mistakes

Common exam mistakes on 9618 Files. Learn what loses marks, then practise the topic with Examiner’s Ink.

Exam tip 1

In an exam, you will almost always get a mark for opening a file in the correct mode and for closing it at the end. Don't forget CLOSEFILE – it's an easy mark to lose! Forgetting to close a file after writing might mean the data is never actually saved.

Exam tip 2

Pay close attention to the question's wording. If it says 'add a new score' or 'log an event', you almost certainly need APPEND mode. If it says 'save the final results' or 'create a report', WRITE mode is often more appropriate.

What happens if I try to open a non-existent file in READ mode?

This will cause a run-time error. Your program will likely crash unless it has error handling routines (which are beyond the scope of the P2 syllabus but good to know about). In an exam, you can assume the file exists unless told otherwise.

What is the difference between `WRITEFILE` and `APPEND`?

This is a common point of confusion. WRITE and APPEND are file modes set when you OPENFILE. WRITEFILE is the command used to write data. You use the WRITEFILE command whether the file was opened in WRITE mode or APPEND mode. The mode determines where the data is written (start of file vs. end of file).

Can I read from and write to a file at the same time?

In Cambridge pseudocode, a file is opened in only one mode at a time (READ, WRITE, or APPEND). To read from a file and then write to it, you would need to open it, read it, close it, and then re-open it in a different mode to write.

Do I need to include the file extension like `.txt` in the filename?

Yes. In pseudocode, the filename is a string literal and should exactly match the name of the file you are targeting, including its extension (e.g., OPENFILE "MyData.txt" FOR READ).