Section 10b

Starting Out with Text Files


 

 

 

 

 

 

 

 

 

 

Introduction To The Text File

As mentioned in the previous topic, the streams you were using previously were related to the computer console (i.e., the keyboard and monitor). You will now be working with file streams. In its simplest definition, file I/O is access to some device that has stored, or is able to store, data. This data can be in one of two forms. It is either in text form, which means the data output to the storage device actually looks just like it did when you outputted it to your monitor screen; or it is in binary form which is a series of ones and zeros representing the data. Generally speaking, binary files are more compact, but they can usually only be viewed by the program that stored them; this is almost always how data is stored in industrial-grade programs.

However, for educational purposes, you will be using text file storage, so that if you save something to a file, you will be able to view it with any editor such as the one on which you are presently developing your programs. Notepad is a small editor included with most Windows™ programs, and can also be used to view the results of your program file storage. This whole process is called file I/O, and you will be storing your data as text files.

For the time being, you will need to include stdio.h library in your programs to make the basic file I/O operations work. Later, you will be using another set of file I/O tools. Stay tuned.

Once you have learned to capture data from files as well as output data to files, you will be able to implement more powerful, and less trivial, programs for your Computer Science learning process. The following topics provide several examples of how this is done.