Content text Unit VIII - File Handling (File Input-output) – C Programming.pdf
www.ckundan.com.np 2 These characters can be interpreted as individual data items or as a component of Strings or numbers. b. Binary Files: In contrast to ASCII files, which contain only characters (plain text), binary files contain additional code information. A binary file is made up of machine readable symbols that represent 1’s and 0’s. The binary file content must be interpreted by a program that understands in advance exactly how it is formatted. These files organize data into blocks containing contagious bytes of information. These blocks represents more complex data structures, such as arrays and structures. 2.System Oriented: System oriented data files are more closely related to the computer’s operating system than stream oriented data files. They are somewhat complicated to work with though their use may be more efficient for certain kinds of application. A separated set of procedures with accompanying library functions is required to process system oriented data files. File Pointer in C: File pointer is a pointer which is used to handle and keep track on the files being accessed. A new data type called “FILE” is used to declare file pointer. This data type is defined in stdio.h file. File pointer is declared as FILE *fp. Where, ‘fp’ is a file pointer. fopen() function is used to open a file that returns a FILE pointer. Once file is opened, file pointer can be used to perform I/O operations on the file. fclose() function is used to close the file. Opening and Closing a Data File: Before a program can write a file or read from a file, the program must open it. Opening a file established a link between the program and the operating system. This provides the operating system, the name of the file and the mode in which the file is to be opened. While working with high level data file, we need buffer area where information is stored temporarily in the course of transferring data between computer memory and data file. The process of establishing a connection between the program and file is called opening file.