I've Got That on File

Keeping your data in variables like structures and arrays is fine as long as once the program is finished, you don't need the data any longer. But for many (perhaps most) real applications, this stipulation does not apply. Think about a program like a text editor or a word processor. The whole point of such a program is to update data that was created in the past so that the new version can be accessed in the future. We have to store the document someplace more permanent than the program's memory space.

For this reason, nearly all programming languages have some facility for such non-volatile storage. Data stored outside the program's memory is usually said to reside in files . Files may be grouped together in directories . Within any directory, all file names are unique. So any file on the system may be uniquely identified by the directory it resides in and its name.

Each file may be of a different type. The libraries for C identify two types of files, text files and binary files. In the UNIX environment, there is no distinction between the two file types. In other environments and for text files, the library emulates the UNIX line convention which is to mark the end of every line with a single newline character. Even when developing code in UNIX, however, it is good practice to distinguish between binary and text files in order to maintain portability.

You should use a text file when the contents of the file are represented as lines of text which could be edited with a text editor. If the data to be stored in the file will be represented using the internal binary representations of integers, structures, arrays, etc, then you should use a binary file.

Which of these would require using a binary file?

A list of student names and phone numbers where each is stored in an array of strings

A structure containing the floating point coordinates of a point

An array of structures each containing the name and integer ID number of a student

A list of all the past presidents of the U.S.