Easy Tutorial
❮ C Examples Read File Home ❯

C Library Function - fclose()

C Standard Library - <stdio.h>

Description

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

Declaration

Here is the declaration for the fclose() function.

int fclose(FILE *stream)

Parameters

Return Value

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

Example

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

#include <stdio.h>

int main()
{
   FILE *fp;

   fp = fopen("file.txt", "w");

   fprintf(fp, "%s", "这里是 tutorialpro.org");
   fclose(fp);

   return(0);
}

Let's compile and run the above program, which will create a file file.txt, write the following text line into it, and finally close the file using the fclose() function.

这里是 tutorialpro.org

C Standard Library - <stdio.h>

❮ C Examples Read File Home ❯