codescracker


c

C fclose()



« Previous Function Next Function »


fclose()

The fclose() function is used to close the file that associated with stream and then flushes its buffer. After a call to fclose() function, stream is no longer connected with the file, and any automatically allocated buffers are deallocated.

fclose() Syntax

Following is the syntax of the fclose() function :

#include<stdio.h>
int fclose(FILE *stream);

fclose() functions returns zero on success, otherwise it returns EOF.

fclose() Example

Following c program opens and then closes the file :

#include<stdio.h>
#include<conio.h>
void main()
{
	clrscr();
	FILE *fp;
	char fname[20];
	printf("Enter the file name with extension (like demo.txt) : ");
	gets(fname);
	fp=fopen(demo, "rb");
	if(fp==NULL)
	{
		printf("Error in opening the file..!!\n");
		printf("Press any key to exit..\n");
		getch();
		exit(1);
	}
	if(fclose(fp))
	{
		printf("Error in closing the file..!!\n");
	}
	getch();
}

« Previous Function Next Function »



Tools
Calculator

Quick Links
Signup - Login - Give Online Test