Introduction to File Processing
Applications of File Processing usually involve tremendous amount of data to be read or written to an auxiliary storage. Hence to save the information on the disk we use data files. File is a collection of numbers, symbols and text placed on the disk. In due course of time files may be read and modified as per the user requirements. Thus, files allow us to store information lastingly in the disk; access and further it may be altered depending upon the needs. This process leads to the concept of data files.
Data Files
Many applications need that information be written to or read from an auxiliary memory device. For such kind of information is stored on the memory device in the form of a data files. Thus, data files allow us to save information permanently, and to access and alter that information whenever necessary. There are two main different types of data files, known stream oriented (or standard) data files, & system oriented (or low level) data files. Stream data files are most commonly used because it is much easier to work with this. These type of data file uses the following function such as printf( ) and scanf( ) function. System-oriented data files are more closely enclosed to the computer's operating system than stream-oriented data files.
Opening a Files
Opening a file establishes a link among the program and the operating system. The link b/w our program and the operating system is a structure called File, that has been defined, in the header file "stdio.h" (standing for standard input/output header file).
We make the following declaration before opening the file,
FILE *fptr;
Each file we open will have its own FILE structure. The FILE structure keeps information about the file being used, such as its current size and its location in memory etc. For example:
FILE *fptr;
fptr=fopen ("Net.c","r");
Here fptr is a pointer variable, that contains address of the structure FILE that has been defined in the header file "stdio.h". fopen() will open a file "Net.c" in 'read' mode, which tells the C compiler that we would be reading the contents of the file.