This documentation is copyright © 1998-2001 Sandro Sigala <sandro@sigala.it>.
All rights reserved.
Released under the GNU General Public License.
fopen
Prototype
#include <stdio.h>
FILE *fopen(const char *filename, const char *mode);
Description
Opens the specified file filename
and returns a stream
associated with it. If the open operation fails, returns NULL
.
The mode
string specifies the operations
that might be done on the stream,
as summarized by the \vpageref[table below][table ]{tbl:fopen_modes}:
\begin{table}[!htp]
\begin{center}
\begin{tabular}{|l|p{10cm}|}
\hline
\hline
\textsc{Mode} & \textsc{Description} \\
\hline
\texttt{r} & Open text file for reading \\
\texttt{w} & Truncate to zero length or create text file for writing \\
\texttt{a} & Append; open or create text file for writing at end-of-file \\
\texttt{rb} & Open binary file for reading \\
\texttt{wb} & Truncate to zero length or create binary file for writing \\
\texttt{ab} & Append; open or create binary file for writing at end-of-file \\
\texttt{r+} & Open text file for update (reading and writing) \\
\texttt{w+} & Truncate to zero length or create text file for update, writing at end-of-file \\
\texttt{a+} & Append; open or create text file for update, writing at end-of-file \\
\texttt{r+b} \textit{or} \texttt{rb+} & Open binary file for update (reading and writing) \\
\texttt{w+b} \textit{or} \texttt{wb+} & Truncate to zero length or create binary file for update, writing at end-of-file \\
\texttt{a+b} \textit{or} \texttt{ab+} & Append; open or create binary file for update, writing at end-of-file \\
\hline
\end{tabular}
\caption{The \texttt{fopen} opening modes.}
\label{tbl:fopen_modes}
\end{center}
\end{table}
References
ISO C 9899:1990 7.9.5.2