C library function -fclose()

C Standard Library - <stdio.h>

Description

C Library Functionsint fclose(FILE *stream)Close the stream. Flush all buffers.

Declaration

Below is the declaration of the fclose() function.

int fclose(FILE *stream)

Parameter

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

Return Value

If the stream is successfully closed, the method returns zero. If it fails, it returns EOF.

Example

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

Example

#include <stdio.h>

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

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

Let us compile and run the above program, which will create a file.file.txt, then write the following text line, and finally usefclose()The function closes the file.

这里是 example.com

C Standard Library - <stdio.h>

other extensions