READFILE: reading a line of text
Reads the next line of text from the open file Names.txt into the STRING variable LineOfText. Each READFILE call reads the following line. Declare the variable first.
Understanding READFILE: reading a line of text in IGCSE Computer Science Paper 2
What it does: A line of text is a string, so the variable that receives it must be declared as STRING before READFILE uses it. The file keeps track of its position, so the second READFILE reads the line after the one read by the first.
Common mistakes: Quotes make OUTPUT display the words TextLine instead of the line read from the file. It should be OUTPUT TextLine, with no quotes, so the variable's contents are displayed. READFILE needs the file opened in READ mode. WRITE mode would replace the file's data with an empty file. It should be OPENFILE "Names.txt" FOR READ.
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
READFILE "Names.txt", LineOfTextFill in the Blanks
Spot the Error
Student with a class code? Join your class →