Next: Standard file pointers Up: C File Handling Previous: C File Handling

Opening a file pointer using fopen

Your program must open a file before it can access it. This is done using the fopen function, which returns the required file pointer. If the file cannot be opened for any reason then the value NULL will be returned. You will usually use fopen as follows

  if ((output_file = fopen("output_file", "w")) == NULL)
           fprintf(stderr, "Cannot open %s\n", "output_file");
fopen takes two arguments, both are strings, the first is the name of the file to be opened, the second is an access character, which is usually one of:

As usual, use the man command for further details by typing man fopen.
Tue Jan 17 11:40:37 GMT 1995