Grade 12 · Practical
Arrays and file handling
Programming Fundamentals · about 3 min
Grade 12 combines arrays with text files so programs can process and persist bulk data.
Key points- Declare typed arrays and process them with loops (total, search, sort, count).
- Text files: `AssignFile(f, name)`, then `Reset` (read) / `Rewrite` (new write) / `Append` (add to end).
- Read line by line with `Readln`; loop `while not Eof(f) do`; write with `Writeln`; ALWAYS `CloseFile(f)` when done.
- Check a file exists with `FileExists(name)` before opening to read.
- Array — an indexed collection processed with loops.
- EOF — end-of-file; the marker that stops a read loop.
EXAM TIP
the file-read template is FileExists → AssignFile → Reset → while not Eof do Readln → CloseFile. Forgetting CloseFile loses marks.