Chapter 22 File Input and Output

File input and output in Microsoft Windows applications are similar to file input and output in standard C run-time programs. However, there are enough differences between the two environments to make a review of file input and output important. For example, although you can use C run-time, stream input and output (I/O) functions in Windows, it's preferable to use the low-level, C run-time input and output functions. Also, since Windows is a multitasking environment, you need to manage open files carefully.

In Windows, your application should use the OpenFile function to work with files. OpenFile opens and manages your files; it returns a file handle that you can use with the low-level, C run-time functions to read and write data.

This chapter covers the following topics:

Handling files in the Windows environment

Using the OpenFile function to create, open, close, reopen, prompt for, and check the status of disk files

Using the low-level, C run-time input and output functions to read from and write to disk files

This chapter also explains how to create a sample application, EditFile, that
illustrates some of these concepts.