C fclose() function

Education is not limited to just classrooms. It can be gained anytime, anywhere... - Ravi Ranjan (M.Tech-NIT)

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.
[box]

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

[/box]

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