display | more...


A function in the ANSI C library


#include <stdio.h>

FILE *fopen(const char *filename, const char *mode);


This function opens a stream corresponding to the named filename with the given mode. The mode can be one of the following:

Open an existing file for reading.
Create a new file (or truncate an existing file) and open it for writing.
Open an existing file (or create a new one) for writing. The file pointer is positioned to the end of the file before every write.

Followed by any of these characters:

Force the file to be open in binary mode instead of the default mode.

When called to open the console in binary mode, `fopen' will disable the generation of SIGINT when you press Ctrl-C (Ctrl-Break will still cause SIGINT), because many programs that use binary reads from the console will also want to get the '\003' (^C) characters. (Examples include NetPBM tools.) You can use the __djgpp_set_ctrl_c library function if you want `Ctrl-C' to generate interrupts while console is read in binary mode.

Force the file to be open in text mode instead of the default mode.
Open the file as with O_RDWR so that both reads and writes can be done to the same file.

If the file is open for both reading and writing, you must call fflush, fseek, or rewind before switching from read to write or from write to read.

The open file is set to line buffered if the underlying object is a device (stdin, stdout, etc), or is fully buffered if the underlying object is a disk file (pr0n.jpg, etc).

If 'b' or 't' is not specified in MODE, the file type is chosen by the value of _fmode.

If you need to specify the DOS share flags use the __djgpp_share_flags.

Return Value

A pointer to the FILE object, or NULL if there was an error.



Source: DJGPP documentation
(return to) C Library Metanode

Log in or register to write something here or to contact authors.