Open a file and close it : File Open « File « C / ANSI-C






Open a file and close it

#include <stdio.h>
#include <stdlib.h>

int main(void)
{
  FILE *fp;

  if((fp = fopen("test", "rb")) == NULL) {
    printf("Cannot open file.\n");
    exit(1);
  }

  if( fclose( fp )) 
      printf("File close error.\n");

  return 0;
}


           
       








Related examples in the same category

1.Get file name from command line and open the file
2.Reopen a file
3. Open a file: how to use fopen
4. Reopen a stream with a different file and mode: how to use freopen
5.Open a file for read