Course Content
Paper 2 – Problem Solving Approach -Practical
0/102
Past Paper-2 May/June 2025
Past Paper-1 May/June 2025
Download Files
0/1
Olevel : Computer Science 2210 / IGCSE 0478 : Recorded

Hello students, welcome back to your Computer Science lesson. In today’s video, we are going to learn file handling using arrays, exactly according to the Computer Science syllabus. By the end of this video, you will clearly understand why arrays are used with files and how data is read from a file into an array using correct exam-style pseudocode.

In real-life programs, data is often stored in files so that it is not lost when the program ends. However, we cannot process file data directly again and again. For this reason, data is read from a file and stored in an array. This makes it easier to access the data quickly, perform operations such as searching or sorting, and display the data whenever required. In this way, arrays act as temporary storage in memory, while files are used for permanent storage on secondary storage devices.

Before looking at the pseudocode, it is important to revise a few key concepts. A file is used to store data permanently on secondary storage, whereas an array is used to store multiple values of the same data type in memory. When reading from a file, data is read line by line, and each line is stored in a single element of the array. This method of using files with arrays is very important for writing clear and correct answers in examinations.

Let us now look at a standard style pseudocode example in which data is read from a file and stored into an array. First, the file STUDENTFILE is opened in READ mode so that existing data can be accessed. An array called Names is then declared, which is capable of storing five string values, such as student names. An integer variable called Index is also declared and used to control the position within the array.

The Index variable is initially set to 1. A WHILE loop is then used, which continues to run until the end of the file is reached, indicated by the EOF condition. Inside the loop, one line of data is read from the file and stored in the array at position Names[Index]. After storing the data, the Index value is increased by 1 so that the next value is stored in the next array position. Once all the data has been read, the file is closed to free system resources.

The EOF, or End Of File, condition is very important because it prevents the program from reading beyond the available data in the file. If EOF is not used correctly, the program may attempt to read data that does not exist, leading to runtime errors. Such mistakes are heavily penalized by examiners, so proper use of EOF is essential.

For Computer Science exams, always use correct pseudocode keywords such as OPENFILE, READ, and CLOSEFILE. Make sure the array is clearly declared with its correct data type and size. A loop using the EOF condition should always be shown, and the pseudocode should be written neatly and logically. Even small syntax or logical errors can result in the loss of marks.

In today’s lesson, we learned how file handling works with arrays in O-Level Computer Science 2210. Files are used to store data permanently, while arrays allow that data to be processed efficiently in memory. If you found this video helpful, don’t forget to like, share, and subscribe. See you in the next lesson, and happy coding.

You cannot copy content of this page