fclose():
- It is used to close the file after use.
- It is recommended to release every resource(file) after use.
- After working resource, releasing a resource is called Proper shut down.
- Improper shutdown causes loss of data.
- Prototype is:
- int fclose(FILE* stream);
- On success, it returns 0.
- On Failure, it returns -1.
#include<stdio.h>
int main()
{
FILE* p;
int r1, r2;
p = fopen("code.c", "r");
if(p != NULL)
{
r1 = fclose(p);
printf("On success : %d \n", r1);
r2 = fclose(p);
printf("On failure : %d \n", r2);
}
return 0;
}