Published online by Cambridge University Press: 17 July 2025
So far the programs are written following the console I/O operations. The inputs are taken through keyboard, these inputs and calculated data are stored in the memory, i.e., in the RAM and output is shown through VDU. But there are some problems related to this system when we need to handle large volume of data. As the data are stored in the main memory, the entire data set is lost as soon as the program is terminated. So for next execution of the program we need to enter the entire inputs. It is very tedious and time consuming to take input a large volume of data through keyboard every time the program executes. Thus it would be much better if we able to store these data permanently so that we can read back whenever required. The solution is file as file is the only place where the data can be stored permanently. C supports a large set of library functions for file handling. These are known as disk I/O or file I/O functions. In this chapter, we will discuss about files I/O functions which help us to know how to write data in files and how to read data from files. These are almost similar to console I/O functions except that these are operated on files.
WHAT IS A FILE?
A file can be defined as a repository of data or more preciously collection of bytes stored on a secondary storage device as it is permanent storage of data. Depending on the interpretation of these bytes several types of file may form. It may form textual document, a database file, an image file or file of any other form. The type of a particular file is decided entirely by the data structures and operations used by a program to process the file.
Depending on the way a file is opened for processing, a file can be classified as a text file or a binary file. The mode of opening a particular file differs in three main areas.
To save this book to your Kindle, first ensure no-reply@cambridge-org.demo.remotlog.com is added to your Approved Personal Document E-mail List under your Personal Document Settings on the Manage Your Content and Devices page of your Amazon account. Then enter the ‘name’ part of your Kindle email address below. Find out more about saving to your Kindle.
Note you can select to save to either the @free.kindle.com or @kindle.com variations. ‘@free.kindle.com’ emails are free but can only be saved to your device when it is connected to wi-fi. ‘@kindle.com’ emails can be delivered even when you are not connected to wi-fi, but note that service fees apply.
Find out more about the Kindle Personal Document Service.
To save content items to your account, please confirm that you agree to abide by our usage policies. If this is the first time you use this feature, you will be asked to authorise Cambridge Core to connect with your account. Find out more about saving content to Dropbox.
To save content items to your account, please confirm that you agree to abide by our usage policies. If this is the first time you use this feature, you will be asked to authorise Cambridge Core to connect with your account. Find out more about saving content to Google Drive.