C fclose() function : <stdio.h>

Closing a File : fclose() function in File Handling

Whenever we open a file in read or write mode then we perform appropriate operations on file and when file is no longer needed then we close the file.
FILE close will flush out all the entries from buffer.

Important :

  1. After performing all Operations , FILE is no longer needed
  2. File is closed using fclose() function
  3. All information associated with file is flushed out of buffer
  4. Closing file will prevent misuse of FILE

Syntax : fclose()

int fclose(FILE *fp);

Simple Example :

#include<stdio.h>
int main()
{
FILE *fp;
fp = fopen("INPUT.txt","r") 
  ----------- 
  ----------- 
  ----------- 
  ----------- 
fclose(fp); //File is no longer needed
}

Return Type : fclose()

Action Return Value
On Success 0
On Error NULL