HP C/iX Library Reference Manual (30026-90004)
Chapter 5 157
HP C/iX Library Function Descriptions
fopen
fopen
Opens a stream.
Syntax
#include <stdio.h>
FILE *fopen (const char *
fname
, const char *
mode
);
Parameters
fname
A pointer to a character string containing the name of the file.
mode
A pointer to a character string defining the mode of the file open.
Return Values
x If successful, a pointer to the FILE structure associated with the stream.
NULL The file open operation failed.
Description
The fopen function opens the file named by
fname
and associates a stream with it. This
function returns a pointer to the FILE structure associated with the stream.
Opening a file in read mode fails if the file does not exist or cannot be read.
When a file is opened for update, both input and output may be done on the resulting
stream. Do not directly follow output with input without an intervening call to fflush()
or to a file positioning function (fseek(), fsetpos(), or rewind()). Do not directly follow
input with output without an intervening call to a file positioning function unless the input
operation encounters end-of-file.
When a file is opened for appending, it is impossible to overwrite information already in
the file. The fseek function can be used to reposition the file pointer to any position in the
file, but when output is written to the file, the current file pointer is disregarded. All
output is written at the end of the file and the file pointer is repositioned at the end of the
output. When opening a binary file the file position indicator may, in some cases, be
positioned beyond the last data written because of blank or null padding.
When opened, a stream is fully buffered only if it can be determined not to refer to an
interactive device. The error and end-of-file indicators for a stream are cleared.
The
mode
parameter points to a character string beginning with one of the following
sequences:
r Open or create text stream for reading.
w Open or create text stream for writing. Truncate to zero length.
a Open or create text stream in append mode. All writes are at end-of-file.