fopen
Opens a file and associates a stream with it
#include <stdio.h> FILE *fopen ( const char *filename, const char *mode);
The fopen function returns a pointer to the object controlling the stream. This pointer must be passed as a parameter to subsequent functions for performing operations on the file. If the open operation fails, fopen returns NULL. If an error occurs, errno is set.
This function also works on the DOS partition.
The fopen function opens the file whose name is the string pointed to by filename, and associates a stream with it. The argument mode points to a string beginning with one of the following sequences:
Opening a file with read mode (r as the first character in the mode argument) fails if the file does not exist or if it cannot be read. Opening a file with append mode (a as the first character in the mode argument) causes all subsequent writes to the file to be forced to the current end-of-file, regardless of previous calls to the fseek function. When a file is opened with update mode (+ as the second or third character of the mode argument), both input and output can be performed on the associated stream.
NOTE:For an example of how to reverse the effect of redirecting stdin, see the example for fdopen.
#include <stdio.h> main () { char filename[13]; FILE *fp; strcpy (filename, "REPORTAA.DAT"); fp = fopen (filename, "r"); /* Do something */
fclose (fp); }