Closing File : Fclose Function in C Programming
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 :
- After performing all Operations , FILE is no longer needed
- File is closed using fclose() function
- All information associated with file is flushed out of buffer
- 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 |