| Data File Handling through C |
| |
| Creating a data file |
| |
| A data file must be created before it can be processed. |
| |
| A stream-oriented data file can be created in two ways. One is to create the file directly, using a text editor or a word processor. |
| |
| The other is to write a program that enters information into the computer and than writes it out to the data file. |
| |
| Unformatted data files can only be created with such specially written programs. |
| |
| Example: |
| |
| Reading a data file- |
| |
| The following program will read a line of text from a data
file on a character by character basis, and display the text on the screen. |
| |
| The program makes use of the library functions get and putchar to read and display the data. |
| |
| An example program to read a line of text from a data file and display it on the screen: |
| |
 |
| |
| Data file consisting
entirely of strings can often be created and read more casually with programs
that utilize special string-oriented library functions. |
| |
| Some commonly used functions of this type are
gets, puts, fgets and fputs. |
| |
| The functions gets and puts read or write strings to or from the standard output devices, whereas fgets and fputs exchange strings with data files. |
| |
| |
| |
| |
| |