9618 · 10.3
Files — FAQ
Frequently asked questions for 9618 Files. Direct answers first, then deeper explanation — then practise with marking.
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).