Declaration:
unsigned long fopen(char file_name[], char mode[]);
Description
Opens a stream.
fopen opens the file specified by file_name and associates a stream with it. fopen returns an unsigned long value to be used as the stream identificator in subsequent operations. The mode string used in calls to fopen is one of the following values:
Value Description
---------------------------
r Open for reading only.
w Create for writing.
a Append; open for writing at the end-of-file or create for writing, if the file does not exist.
r+ Open an existing file for update (reading and writing).
w+ Create a new file for update.
a+ Open for append; open (or create, if the file does not exist) for update at the end of file.
To specify that the given file is being opened or created in the text mode, append t to the value of the type string (for example, rt or w+t).
Similarly, to specify the binary mode, append b to the type string (for example, rb or w+b). If t or b is not given in the type string, then the mode is controlled by the _fmode global variable. If _fmode is set to O_BINARY, then files will be opened in the binary mode. If _fmode is set to O_TEXT, then files will be opened in the text mode.
Note. The O_* constants are defined in file system.h.
When a file is opened for update, both input and output can be done on the resulting stream; however,
•
|
output cannot be directly followed by input without intervening fseekor rewind;
|
•
|
input cannot be directly followed by output without intervening fseek, rewind, or an input that encounters the end-of-file.
|
Returned Value
On successful completion fdopen returns the unsigned long identifying the stream. In the event of error, it returns 0.
|