fopen

Opens a file by returning the address of a FILE structure.

Format

#include  <stdio.h>

FILE *fopen  (const char *file_spec, const char
             *a_mode); 
             (ANSI C)

FILE *fopen  (const char *file_spec, const char
             *a_mode, . . . ); (DEC C Extension)

Arguments

file_spec
A character string containing a valid file specification.
a_ mode
The access mode indicator. Use one of the following character strings: "r", "w", "a", "r+", "w+", "rb", "r+b", "rb+", "wb", "w+b", "wb+", "ab", "a+b", "ab+", or "a+".

These access modes have the following effects:

The update access modes allow a file to be opened for both reading and writing. When used with existing files, "r+" and "a+" differ only in the initial positioning within the file. The modes are as follows:

. . .
Optional file attribute arguments. The file attribute arguments are the same as those used in the creat function. For more information, see the creat function.

Description

If a version of the file exists, a new file created with fopen inherits certain attributes from the existing file unless those attributes are specified in the fopen call. The following attributes are inherited:
Record format
Maximum record size
Carriage control
File protection.

If you specify a directory in the file name and it is a search list that contains an error, DEC C for OpenVMS Systems interprets it as a file open error.

The file control block can be freed with the fclose function, or by default on normal program termination.

Return Values
File pointer. 
NULL  Indicates an error. The constant NULL is defined in the <stdio.h> header file to be the NULL pointer value. The function returns NULL to signal the following errors:

  • File protection violations

  • Attempts to open a nonexistent file for read access

  • Failure to open the specified file
 


Previous Page | Next Page | Table of Contents | Index