C library function - fclose()

Advertisements


Description

The C library function int fclose(FILE *stream) closes the stream. All buffers are flushed.

Declaration

Following is the declaration for fclose() function.

int fclose(FILE *stream)

Parameters

  • stream -- This is the pointer to a FILE object that specifies the stream to be closed.

Return Value

This method returns zero if the stream is successfully closed.On failure, EOF is returned.

Example

The following example shows the usage of fclose() function.

#include <stdio.h>

int main()
{
   FILE *fp;
 
   fp = fopen("file.txt", "w");

   fprintf(fp, "%s", "This is tutorialspoint.com");
   fclose(fp);
   
   return(0);
}

Let us compile and run the above program, this will create a file file.txt, second it will write following text line and finally it will close the file using fclose() function.

This is tutorialspoint.com


Advertisements
Advertisements