Skip to main content
Contents Index
Dark Mode Prev Up Next
\(\newcommand{\N}{\mathbb N}
\newcommand{\Z}{\mathbb Z}
\newcommand{\Q}{\mathbb Q}
\newcommand{\R}{\mathbb R}
\newcommand{\lt}{<}
\newcommand{\gt}{>}
\newcommand{\amp}{&}
\definecolor{fillinmathshade}{gray}{0.9}
\newcommand{\fillinmath}[1]{\mathchoice{\colorbox{fillinmathshade}{$\displaystyle \phantom{\,#1\,}$}}{\colorbox{fillinmathshade}{$\textstyle \phantom{\,#1\,}$}}{\colorbox{fillinmathshade}{$\scriptstyle \phantom{\,#1\,}$}}{\colorbox{fillinmathshade}{$\scriptscriptstyle\phantom{\,#1\,}$}}}
\)
Section 15.1 File I/O Overview
So far, the only way in which we have been able to supply data to our code is via interaction with the user at runtime. We call such program use "interactive"
\(-\) the user supplies input.
Input to a program can also come from a data file and this is sometimes called batch mode
\(-\) a data file provides input to the code.
A data file \(-\) is stored somewhere and accessed by your program. The storage location could be your hard disk, a CD-ROM (remember those?), a flash drive, etc.
In C, there are three steps that are necessary to execute in the following order when attempting to read from or write to a file:
Open file
Read/write to/from file
Close file
We will now learn about each of these steps in detail.
Investigate 15.1 .
What do you think are some benefits gained from receiving input from a data file as opposed to interactive user input?