Which of the following function is used to open a file in C++?

The keyword parameters can be passed in mixed case. They must be separated by commas. Only one instance of a keyword can be specified.

The file name passed to fopen() often determines the type of file that is opened. A set of file-naming rules exist, which allow you to create an application that references both MVS™ and HFS files specifically. For details on how fopen() determines the type of file from the filename and mode strings, see the topics about opening files in z/OS XL C/C++ Programming Guide.

Large file support for z/OS® UNIX files: Large z/OS UNIX files are supported automatically for AMODE 64 C/C++ applications. AMODE 31 C/C++ applications must be compiled with the option LANGLVL(LONGLONG) and define the _LARGE_FILES feature test macro before any headers are included to enable this function to operate on z/OS UNIX files that are larger than 2 GB in size. File size and offset fields are enlarged to 63 bits in width. Therefore, any other function operating on the file is required to define the _LARGE_FILES feature test macro as well.

Named pipes in multithreaded environment: Do not use fopen() to open named pipes in multithreaded environment. If used, a deadlock will occur. See z/OS XL C/C++ Programming Guide for a detailed explanation.

File mode

Restriction: When running with POSIX(OFF) and specifying a mode parameter that includes t, for example, rt, rt+, r+t, wt, wt+, w+t, at,

/* CELEBF26                                      

   This example attempts to open two files for reading, myfile.dat              
   and myfile2.dat.                                                             
                                                                                
 */                                                                             
#include                                                               
                                                                                
int main(void)                                                                  
{                                                                               
   FILE *stream;                                                                
                                                                                
   /* The following call opens a text file for reading */                       
                                                                                
   if ((stream = fopen("myfile.dat", "r")) == NULL)                             
      printf("Could not open data file for reading\n");                         
                                                                                
   /* The following call opens:                                                 
              the file myfile2.dat,                                             
              a binary file for reading and writing,                            
              whose record length is 80 bytes,                                  
              and maximum length of a physical block is 240 bytes,              
              fixed-length, blocked record format                               
              for sequential record I/O.                                        
   */                                                                           
                                                                                
   if ( (stream = fopen("myfile2.dat", "rb+, lrecl=80,\                         
      blksize=240, recfm=fb, type=record")) == NULL )                           
      printf("Could not open data file for read update\n");                     
}                                                                               
0 or
/* CELEBF26                                      

   This example attempts to open two files for reading, myfile.dat              
   and myfile2.dat.                                                             
                                                                                
 */                                                                             
#include                                                               
                                                                                
int main(void)                                                                  
{                                                                               
   FILE *stream;                                                                
                                                                                
   /* The following call opens a text file for reading */                       
                                                                                
   if ((stream = fopen("myfile.dat", "r")) == NULL)                             
      printf("Could not open data file for reading\n");                         
                                                                                
   /* The following call opens:                                                 
              the file myfile2.dat,                                             
              a binary file for reading and writing,                            
              whose record length is 80 bytes,                                  
              and maximum length of a physical block is 240 bytes,              
              fixed-length, blocked record format                               
              for sequential record I/O.                                        
   */                                                                           
                                                                                
   if ( (stream = fopen("myfile2.dat", "rb+, lrecl=80,\                         
      blksize=240, recfm=fb, type=record")) == NULL )                           
      printf("Could not open data file for read update\n");                     
}                                                                               
1, the fopen() request will fail with a message indicating a non-valid mode was specified.

Table 1. Values for the Positional ParameterFile ModeGeneral DescriptionrOpen a text file for reading. (The file must exist.)wOpen a text file for writing. If the

/* CELEBF26                                      

   This example attempts to open two files for reading, myfile.dat              
   and myfile2.dat.                                                             
                                                                                
 */                                                                             
#include                                                               
                                                                                
int main(void)                                                                  
{                                                                               
   FILE *stream;                                                                
                                                                                
   /* The following call opens a text file for reading */                       
                                                                                
   if ((stream = fopen("myfile.dat", "r")) == NULL)                             
      printf("Could not open data file for reading\n");                         
                                                                                
   /* The following call opens:                                                 
              the file myfile2.dat,                                             
              a binary file for reading and writing,                            
              whose record length is 80 bytes,                                  
              and maximum length of a physical block is 240 bytes,              
              fixed-length, blocked record format                               
              for sequential record I/O.                                        
   */                                                                           
                                                                                
   if ( (stream = fopen("myfile2.dat", "rb+, lrecl=80,\                         
      blksize=240, recfm=fb, type=record")) == NULL )                           
      printf("Could not open data file for read update\n");                     
}                                                                               
2 mode is specified for a ddname that has DISP=MOD, the behavior is the same as if
/* CELEBF26                                      

   This example attempts to open two files for reading, myfile.dat              
   and myfile2.dat.                                                             
                                                                                
 */                                                                             
#include                                                               
                                                                                
int main(void)                                                                  
{                                                                               
   FILE *stream;                                                                
                                                                                
   /* The following call opens a text file for reading */                       
                                                                                
   if ((stream = fopen("myfile.dat", "r")) == NULL)                             
      printf("Could not open data file for reading\n");                         
                                                                                
   /* The following call opens:                                                 
              the file myfile2.dat,                                             
              a binary file for reading and writing,                            
              whose record length is 80 bytes,                                  
              and maximum length of a physical block is 240 bytes,              
              fixed-length, blocked record format                               
              for sequential record I/O.                                        
   */                                                                           
                                                                                
   if ( (stream = fopen("myfile2.dat", "rb+, lrecl=80,\                         
      blksize=240, recfm=fb, type=record")) == NULL )                           
      printf("Could not open data file for read update\n");                     
}                                                                               
3 had been specified. Otherwise, if the file already exists, its contents are destroyed.aOpen a text file in append mode for writing at the end of the file. fopen() creates the file if it does not exist.r+Open a text file for both reading and writing. (The file must exist.)w+Open a text file for both reading and writing. If the
/* CELEBF26                                      

   This example attempts to open two files for reading, myfile.dat              
   and myfile2.dat.                                                             
                                                                                
 */                                                                             
#include                                                               
                                                                                
int main(void)                                                                  
{                                                                               
   FILE *stream;                                                                
                                                                                
   /* The following call opens a text file for reading */                       
                                                                                
   if ((stream = fopen("myfile.dat", "r")) == NULL)                             
      printf("Could not open data file for reading\n");                         
                                                                                
   /* The following call opens:                                                 
              the file myfile2.dat,                                             
              a binary file for reading and writing,                            
              whose record length is 80 bytes,                                  
              and maximum length of a physical block is 240 bytes,              
              fixed-length, blocked record format                               
              for sequential record I/O.                                        
   */                                                                           
                                                                                
   if ( (stream = fopen("myfile2.dat", "rb+, lrecl=80,\                         
      blksize=240, recfm=fb, type=record")) == NULL )                           
      printf("Could not open data file for read update\n");                     
}                                                                               
4 mode is specified for a ddname that has DISP=MOD, the behavior is the same as if
/* CELEBF26                                      

   This example attempts to open two files for reading, myfile.dat              
   and myfile2.dat.                                                             
                                                                                
 */                                                                             
#include                                                               
                                                                                
int main(void)                                                                  
{                                                                               
   FILE *stream;                                                                
                                                                                
   /* The following call opens a text file for reading */                       
                                                                                
   if ((stream = fopen("myfile.dat", "r")) == NULL)                             
      printf("Could not open data file for reading\n");                         
                                                                                
   /* The following call opens:                                                 
              the file myfile2.dat,                                             
              a binary file for reading and writing,                            
              whose record length is 80 bytes,                                  
              and maximum length of a physical block is 240 bytes,              
              fixed-length, blocked record format                               
              for sequential record I/O.                                        
   */                                                                           
                                                                                
   if ( (stream = fopen("myfile2.dat", "rb+, lrecl=80,\                         
      blksize=240, recfm=fb, type=record")) == NULL )                           
      printf("Could not open data file for read update\n");                     
}                                                                               
5 had been specified. Otherwise, if the file already exists, its contents are destroyed.a+Open a text file in append mode for reading or updating at the end of the file. fopen() creates the file if it does not exist.rbOpen a binary file for reading. (The file must exist.)wbOpen an empty binary file for writing. If the
/* CELEBF26                                      

   This example attempts to open two files for reading, myfile.dat              
   and myfile2.dat.                                                             
                                                                                
 */                                                                             
#include                                                               
                                                                                
int main(void)                                                                  
{                                                                               
   FILE *stream;                                                                
                                                                                
   /* The following call opens a text file for reading */                       
                                                                                
   if ((stream = fopen("myfile.dat", "r")) == NULL)                             
      printf("Could not open data file for reading\n");                         
                                                                                
   /* The following call opens:                                                 
              the file myfile2.dat,                                             
              a binary file for reading and writing,                            
              whose record length is 80 bytes,                                  
              and maximum length of a physical block is 240 bytes,              
              fixed-length, blocked record format                               
              for sequential record I/O.                                        
   */                                                                           
                                                                                
   if ( (stream = fopen("myfile2.dat", "rb+, lrecl=80,\                         
      blksize=240, recfm=fb, type=record")) == NULL )                           
      printf("Could not open data file for read update\n");                     
}                                                                               
6 mode is specified for a ddname that has DISP=MOD, the behavior is the same as if
/* CELEBF26                                      

   This example attempts to open two files for reading, myfile.dat              
   and myfile2.dat.                                                             
                                                                                
 */                                                                             
#include                                                               
                                                                                
int main(void)                                                                  
{                                                                               
   FILE *stream;                                                                
                                                                                
   /* The following call opens a text file for reading */                       
                                                                                
   if ((stream = fopen("myfile.dat", "r")) == NULL)                             
      printf("Could not open data file for reading\n");                         
                                                                                
   /* The following call opens:                                                 
              the file myfile2.dat,                                             
              a binary file for reading and writing,                            
              whose record length is 80 bytes,                                  
              and maximum length of a physical block is 240 bytes,              
              fixed-length, blocked record format                               
              for sequential record I/O.                                        
   */                                                                           
                                                                                
   if ( (stream = fopen("myfile2.dat", "rb+, lrecl=80,\                         
      blksize=240, recfm=fb, type=record")) == NULL )                           
      printf("Could not open data file for read update\n");                     
}                                                                               
7 had been specified. Otherwise, if the file already exists, its contents are destroyed.abOpen a binary file in append mode for writing at the end of the file. fopen() creates the file if it does not exist.rtOpen a text file for reading. (The file must exist.)wtOpen a text file for writing. If the file already exists, its contents are destroyed.atOpen a text file in append mode for writing at the end of the file. fopen() creates the file if it does not exist.r+b or rb+Open a binary file for both reading and writing. (The file must exist.)w+b or wb+Open an empty binary file for both reading and writing. If the
/* CELEBF26                                      

   This example attempts to open two files for reading, myfile.dat              
   and myfile2.dat.                                                             
                                                                                
 */                                                                             
#include                                                               
                                                                                
int main(void)                                                                  
{                                                                               
   FILE *stream;                                                                
                                                                                
   /* The following call opens a text file for reading */                       
                                                                                
   if ((stream = fopen("myfile.dat", "r")) == NULL)                             
      printf("Could not open data file for reading\n");                         
                                                                                
   /* The following call opens:                                                 
              the file myfile2.dat,                                             
              a binary file for reading and writing,                            
              whose record length is 80 bytes,                                  
              and maximum length of a physical block is 240 bytes,              
              fixed-length, blocked record format                               
              for sequential record I/O.                                        
   */                                                                           
                                                                                
   if ( (stream = fopen("myfile2.dat", "rb+, lrecl=80,\                         
      blksize=240, recfm=fb, type=record")) == NULL )                           
      printf("Could not open data file for read update\n");                     
}                                                                               
8 (or
/* CELEBF26                                      

   This example attempts to open two files for reading, myfile.dat              
   and myfile2.dat.                                                             
                                                                                
 */                                                                             
#include                                                               
                                                                                
int main(void)                                                                  
{                                                                               
   FILE *stream;                                                                
                                                                                
   /* The following call opens a text file for reading */                       
                                                                                
   if ((stream = fopen("myfile.dat", "r")) == NULL)                             
      printf("Could not open data file for reading\n");                         
                                                                                
   /* The following call opens:                                                 
              the file myfile2.dat,                                             
              a binary file for reading and writing,                            
              whose record length is 80 bytes,                                  
              and maximum length of a physical block is 240 bytes,              
              fixed-length, blocked record format                               
              for sequential record I/O.                                        
   */                                                                           
                                                                                
   if ( (stream = fopen("myfile2.dat", "rb+, lrecl=80,\                         
      blksize=240, recfm=fb, type=record")) == NULL )                           
      printf("Could not open data file for read update\n");                     
}                                                                               
9) mode is specified for a ddname that has DISP=MOD, the behavior is the same as if t0 had been specified. Otherwise, if the file already exists, its contents are destroyed.a+b or ab+Open a binary file in append mode for reading or updating at the end of the file. fopen() creates the file if it does not exist.r+t or rt+Open a text file for both reading and writing. (The file must exist.)w+t or wt+Open a text file for both reading and writing. If the file already exists, its contents are destroyed.a+t or at+Open a text file in append mode for reading or updating at the end of the file. fopen() creates the file if it does not exist.

Attention: Use the

/* CELEBF26                                      

   This example attempts to open two files for reading, myfile.dat              
   and myfile2.dat.                                                             
                                                                                
 */                                                                             
#include                                                               
                                                                                
int main(void)                                                                  
{                                                                               
   FILE *stream;                                                                
                                                                                
   /* The following call opens a text file for reading */                       
                                                                                
   if ((stream = fopen("myfile.dat", "r")) == NULL)                             
      printf("Could not open data file for reading\n");                         
                                                                                
   /* The following call opens:                                                 
              the file myfile2.dat,                                             
              a binary file for reading and writing,                            
              whose record length is 80 bytes,                                  
              and maximum length of a physical block is 240 bytes,              
              fixed-length, blocked record format                               
              for sequential record I/O.                                        
   */                                                                           
                                                                                
   if ( (stream = fopen("myfile2.dat", "rb+, lrecl=80,\                         
      blksize=240, recfm=fb, type=record")) == NULL )                           
      printf("Could not open data file for read update\n");                     
}                                                                               
2,
/* CELEBF26                                      

   This example attempts to open two files for reading, myfile.dat              
   and myfile2.dat.                                                             
                                                                                
 */                                                                             
#include                                                               
                                                                                
int main(void)                                                                  
{                                                                               
   FILE *stream;                                                                
                                                                                
   /* The following call opens a text file for reading */                       
                                                                                
   if ((stream = fopen("myfile.dat", "r")) == NULL)                             
      printf("Could not open data file for reading\n");                         
                                                                                
   /* The following call opens:                                                 
              the file myfile2.dat,                                             
              a binary file for reading and writing,                            
              whose record length is 80 bytes,                                  
              and maximum length of a physical block is 240 bytes,              
              fixed-length, blocked record format                               
              for sequential record I/O.                                        
   */                                                                           
                                                                                
   if ( (stream = fopen("myfile2.dat", "rb+, lrecl=80,\                         
      blksize=240, recfm=fb, type=record")) == NULL )                           
      printf("Could not open data file for read update\n");                     
}                                                                               
4,
/* CELEBF26                                      

   This example attempts to open two files for reading, myfile.dat              
   and myfile2.dat.                                                             
                                                                                
 */                                                                             
#include                                                               
                                                                                
int main(void)                                                                  
{                                                                               
   FILE *stream;                                                                
                                                                                
   /* The following call opens a text file for reading */                       
                                                                                
   if ((stream = fopen("myfile.dat", "r")) == NULL)                             
      printf("Could not open data file for reading\n");                         
                                                                                
   /* The following call opens:                                                 
              the file myfile2.dat,                                             
              a binary file for reading and writing,                            
              whose record length is 80 bytes,                                  
              and maximum length of a physical block is 240 bytes,              
              fixed-length, blocked record format                               
              for sequential record I/O.                                        
   */                                                                           
                                                                                
   if ( (stream = fopen("myfile2.dat", "rb+, lrecl=80,\                         
      blksize=240, recfm=fb, type=record")) == NULL )                           
      printf("Could not open data file for read update\n");                     
}                                                                               
6,
/* CELEBF26                                      

   This example attempts to open two files for reading, myfile.dat              
   and myfile2.dat.                                                             
                                                                                
 */                                                                             
#include                                                               
                                                                                
int main(void)                                                                  
{                                                                               
   FILE *stream;                                                                
                                                                                
   /* The following call opens a text file for reading */                       
                                                                                
   if ((stream = fopen("myfile.dat", "r")) == NULL)                             
      printf("Could not open data file for reading\n");                         
                                                                                
   /* The following call opens:                                                 
              the file myfile2.dat,                                             
              a binary file for reading and writing,                            
              whose record length is 80 bytes,                                  
              and maximum length of a physical block is 240 bytes,              
              fixed-length, blocked record format                               
              for sequential record I/O.                                        
   */                                                                           
                                                                                
   if ( (stream = fopen("myfile2.dat", "rb+, lrecl=80,\                         
      blksize=240, recfm=fb, type=record")) == NULL )                           
      printf("Could not open data file for read update\n");                     
}                                                                               
8, and
/* CELEBF26                                      

   This example attempts to open two files for reading, myfile.dat              
   and myfile2.dat.                                                             
                                                                                
 */                                                                             
#include                                                               
                                                                                
int main(void)                                                                  
{                                                                               
   FILE *stream;                                                                
                                                                                
   /* The following call opens a text file for reading */                       
                                                                                
   if ((stream = fopen("myfile.dat", "r")) == NULL)                             
      printf("Could not open data file for reading\n");                         
                                                                                
   /* The following call opens:                                                 
              the file myfile2.dat,                                             
              a binary file for reading and writing,                            
              whose record length is 80 bytes,                                  
              and maximum length of a physical block is 240 bytes,              
              fixed-length, blocked record format                               
              for sequential record I/O.                                        
   */                                                                           
                                                                                
   if ( (stream = fopen("myfile2.dat", "rb+, lrecl=80,\                         
      blksize=240, recfm=fb, type=record")) == NULL )                           
      printf("Could not open data file for read update\n");                     
}                                                                               
9 parameters with care; data in existing files of the same name will be lost.

Text files contain printable characters and control characters organized into lines. Each line ends with a newline character. The system may insert or convert control characters in an output text stream. For example, t6 written to an MVS DASD text file will be treated as if t7 (newline) was written.

Note: When compared, data output to a text stream may not be equal to data input from the same text stream.

Binary files contain a series of characters. For binary files, the system does not translate control characters on input or output. Under z/OS XL C/C++, some types of files are always treated as binary files, even when opened in text mode.

In such cases, a control character is written to the file as binary data. On input, the control character will be read back as it was written. See the topic about the byte stream model in z/OS XL C/C++ Programming Guide for more information.

z/OS XL C/C++ has Record I/O and Blocked I/O file extensions. These files are binary in nature—no data interpretation—and require additional qualifiers: t8 and t9. See the topics about writing to record I/O files and writing to blocked I/O files in z/OS XL C/C++ Programming Guide for more information.

When you open a file with

/* CELEBF26                                      

   This example attempts to open two files for reading, myfile.dat              
   and myfile2.dat.                                                             
                                                                                
 */                                                                             
#include                                                               
                                                                                
int main(void)                                                                  
{                                                                               
   FILE *stream;                                                                
                                                                                
   /* The following call opens a text file for reading */                       
                                                                                
   if ((stream = fopen("myfile.dat", "r")) == NULL)                             
      printf("Could not open data file for reading\n");                         
                                                                                
   /* The following call opens:                                                 
              the file myfile2.dat,                                             
              a binary file for reading and writing,                            
              whose record length is 80 bytes,                                  
              and maximum length of a physical block is 240 bytes,              
              fixed-length, blocked record format                               
              for sequential record I/O.                                        
   */                                                                           
                                                                                
   if ( (stream = fopen("myfile2.dat", "rb+, lrecl=80,\                         
      blksize=240, recfm=fb, type=record")) == NULL )                           
      printf("Could not open data file for read update\n");                     
}                                                                               
3,
/* CELEBF26                                      

   This example attempts to open two files for reading, myfile.dat              
   and myfile2.dat.                                                             
                                                                                
 */                                                                             
#include                                                               
                                                                                
int main(void)                                                                  
{                                                                               
   FILE *stream;                                                                
                                                                                
   /* The following call opens a text file for reading */                       
                                                                                
   if ((stream = fopen("myfile.dat", "r")) == NULL)                             
      printf("Could not open data file for reading\n");                         
                                                                                
   /* The following call opens:                                                 
              the file myfile2.dat,                                             
              a binary file for reading and writing,                            
              whose record length is 80 bytes,                                  
              and maximum length of a physical block is 240 bytes,              
              fixed-length, blocked record format                               
              for sequential record I/O.                                        
   */                                                                           
                                                                                
   if ( (stream = fopen("myfile2.dat", "rb+, lrecl=80,\                         
      blksize=240, recfm=fb, type=record")) == NULL )                           
      printf("Could not open data file for read update\n");                     
}                                                                               
5,
/* CELEBF26                                      

   This example attempts to open two files for reading, myfile.dat              
   and myfile2.dat.                                                             
                                                                                
 */                                                                             
#include                                                               
                                                                                
int main(void)                                                                  
{                                                                               
   FILE *stream;                                                                
                                                                                
   /* The following call opens a text file for reading */                       
                                                                                
   if ((stream = fopen("myfile.dat", "r")) == NULL)                             
      printf("Could not open data file for reading\n");                         
                                                                                
   /* The following call opens:                                                 
              the file myfile2.dat,                                             
              a binary file for reading and writing,                            
              whose record length is 80 bytes,                                  
              and maximum length of a physical block is 240 bytes,              
              fixed-length, blocked record format                               
              for sequential record I/O.                                        
   */                                                                           
                                                                                
   if ( (stream = fopen("myfile2.dat", "rb+, lrecl=80,\                         
      blksize=240, recfm=fb, type=record")) == NULL )                           
      printf("Could not open data file for read update\n");                     
}                                                                               
7, rt3, or t0 mode, all write operations take place at the end of the file. Although you can reposition the file pointer using fseek(), fsetpos(), or rewind(), the write functions move the file pointer back to the end of the file before they carry out any output operation. This action prevents you from overwriting existing data.

When you specify the update mode (using rt5 in the second or third position), you can both read from and write to the file. However, when switching between reading and writing, you must include an intervening positioning function such as fseek(), fsetpos(), rewind(), or fflush(). Output may immediately follow input if the EOF was detected.

Table 2. Keyword Parameters for File ModeParameterDescriptionrt6valueControls whether the runtime library should attempt to recover from an abend issued during OS I/O operations against the stream being opened. The value can be abend or recover. See z/OS XL C/C++ Programming Guide for more information.rt7valueIndicator of the direction of the access of the VSAM data set. The value can be fwd or bwd.rt8Sets the file position indicator to the last record. The access direction may be changed by a call to flocate().rt9Indicates that the file name is not to be converted to uppercase but used as is. This option is the default under POSIX. It is also the default for HFS file names (see z/OS XL C/C++ Programming Guide for more information).rt+0valueSpecifies the maximum length, in bytes, of a physical block of records. To check whether your rt+1 parameter is valid and is within its limits, see the appropriate topic in z/OS XL C/C++ Programming Guide for the type of file you are opening.rt+2Indicator to allow byte seeks for a binary file. For more information, see the ftell() and fseek() functions.rt+3valueSpecifies the length, in bytes, for fixed-length records and the maximum length for variable-length records. To check whether your rt+4 parameter is valid and is within its limits, see the appropriate topic in z/OS XL C/C++ Programming Guide for the type of file you are opening.rt+5Indicates that the stream may not use any of the reposition functions. This may improve performance.rt+6xxxxxxxSpecifies the password for a VSAM data set.rt+7ASA print-control charactersrt+8Fixed-length, unblockedrt+9Fixed-length, ASA print-control charactersr+t0Fixed-length, blockedr+t1Fixed-length, machine print-control codesr+t2Fixed-length, unblocked, standardr+t3Fixed-length, blocked, ASA print-control charactersr+t4Fixed-length, blocked, machine print-control codesr+t5Fixed-length, unblocked, standard ASA print-control charactersr+t6Fixed-length, unblocked, standard, ASA print-control charactersr+t7Fixed-length, unblocked, standard, machine print-control codesr+t8Fixed-length, blocked, standard, ASA print-control charactersr+t9Fixed-length, blocked, standard, machine print-control codeswt0Undefined-lengthwt1Undefined-length, ASA print control characterswt2Undefined-length, machine print control codeswt3Variable, unblockedwt4Variable, ASA print-control characterswt5Variable, blockedwt6Variable, machine print-control codeswt7Variable, unblocked, spannedwt8Variable, blocked, ASA print-control characterswt9Variable, blocked, machine print-control codeswt+0Variable, blocked, spannedwt+1Variable, unblocked, spanned, ASA print-control characterswt+2Variable, unblocked, spanned, machine print-control codeswt+3Variable, blocked, spanned, ASA print-control characterswt+4Variable, blocked, spanned, machine print-control codeswt+5Existing file attributes are used if file is opened in write mode.

Note: Using wt+5 is only valid for existing DASD data sets. It is ignored in all other cases.

wt+7Identical to wt+5 with the following exceptions:
  • If there is no record format for the existing DASD data set, defaults are assigned as if the data set did not exist.
  • When append mode is used, the fopen() fails.
See z/OS XL C/C++ Programming Guide for more information about fopen() default attributes.wt+9This parameter specifies that I/O operations against the stream are restricted to the thread in which the stream was opened. The library will not lock the stream in a multithread environment. Use of this keyword can improve performance when the stream does not need to be accessed on different threads.spaceSpace attributes for MVS data sets. Within the parameter, you cannot have any imbedded blanks.

Where:uunit type of space requestedpprimary amount of space requestedssecondary amount of space requesteddnumber of directory space requested

See the topic about fopen() and freopen() parameters in z/OS XL C/C++ Programming Guide for more information about the syntax of this parameter.

t9This parameter specifies that the file is to be opened for sequential blocked I/O. The file must be opened as a binary file; otherwise, fopen() fails. Read and write operations are done with the fread() and fwrite() functions.w+t1This parameter identifies this file as a memory file that is accessible only from C programs.w+t2If you are using MVS/ESA, you can specify the HIPERSPACE suboption to open a hiperspace memory file.

Restriction: For AMODE 64 applications, w+t2 is treated as w+t1.

t8This parameter specifies that the file is to be opened for sequential record I/O. The file must be opened as a binary file; otherwise, fopen() fails. Read and write operations are done with the fread() and fwrite() functions. This is the default fopen() mode for accessing VSAM clusters.

Returned value

If successful, fopen() returns a pointer to the object controlling the associated stream.

If unsuccessful, fopen() returns a NULL pointer.

fopen() generally fails if parameters are mismatched.

Special behavior for large files for HFS: The following is a possible value of errno:Error CodeDescriptionEOVERFLOWThe named file is a regular file and the size of the file cannot be represented correctly in an object of type w+t6.

How to open a file in C?

Opening a file is performed using the fopen() function defined in the stdio.h header file. The syntax for opening a file in standard I/O is: ptr = fopen("fileopen","mode");

Which of the following are correct file opening modes in C?

Opening File: fopen().

What is the function of files in C?

The process of file handling refers to how we store the available data or info in a file with the help of a program. The C language stores all the data available in a program into a file with the help of file handling in C. This data can be fetched/extracted from these files to work again in any program.