Data file
The data was written to the standard output and data was read from the standard input. As long as only small amount of data are being accessed in the form of simple variables and character strings. This type of I/O is sufficient. However, with large amount of data, the information has to be written to or read from auxiliary device. Such information is stored on the device in the form of a data file.
Different categories of data files
There are two different categories of data files,
1. Stream oriented data files
Stream oriented data files are two types.
o In the first category, the data file comprises consecutive characters. These characters can be interpreted as individual data items or as components of strings or numbers. These are called text files.
o In the second category, often called as unformatted data files, organizes data into blocks containing contiguous bytes of information. These blocks represent more complex data structures, such as arrays and structures. These files are called binary files
2. System oriented data files
o They are more closely related to the computer’s operating system than are stream-oriented data files.
o To perform the I/O form and to files, an extensive set of library functions are available in C.
Text files
Ø Text files are Stream-oriented data files.
Ø The data file comprises consecutive characters. These characters can be interpreted as individual data items or as components of strings or numbers.
Ø A text file contains only textual information like alphabets, digits and special symbols.
Ø In text files, the ASCII codes of alphabets, digits, special symbols are stored.
Ø A good example of a text file is any C program, say program1.c
Ø A new-line character is converted into the carriage return-linefeed combination before being written to the disk. Likewise, the carriage return-linefeed combination on the disk is converted back into a new-line when the file is read by a C program.
Ø A special character, whose ASCII value is 26, is inserted after the last character in the file to mark the end of file. If this character is detected at any point in the file, the read function would return the EOF signal to the program.
Ø The only function that is available for storing numbers in a disk file is the fprintf() function.
Binary files
Ø Binary files are Stream-oriented data files.
Ø Often called as unformatted data files, organizes data into blocks containing contiguous bytes of information. These blocks represent more complex data
structures, such as arrays and structures. These files are called binary files.
Ø A binary file is merely a collection of bytes.
Ø This collection might be a compiled version of a C program (say program1.exe) or music data stored in a wave file or a picture stored in a graphic file.
Ø In text-mode, a new-line character is converted into the carriage return-linefeed combination before being written to the disk. Likewise, the carriage return-linefeed combination on the disk is converted back into a new-line when the file is read by a C program. However, if a file is opened in binary mode, as opposed to text
mode, these conversions will not take place.
Ø In text-mode, a special character, whose ASCII value is 26, is inserted after the last character in the file to mark the end of file. If this character is detected at any
point in the file, the read function would return the EOF signal to the program. However, there is no such special character present in the binary mode files to mark
the end of file. The binary mode files keep track of the end of the file from the number of characters present in the directory entry of the file.
Ø The functions that are available for storing and receiving numbers in a binary file are the fwrite() and fread() function.