Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

C library function - fclose()

C library function - fclose()

C Standard Library - <stdio.h> C Standard Library -

Description

C library function *int fclose(FILE stream) Closes the stream. Flushes all buffers.

Declaration

The following is the declaration of the fclose() function.



int fclose(FILE *stream)

Parameters

Return Value

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

Example

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

Example

#include

int

main

(

)

{

   FILE

fp

;

 

   fp

=

fopen

(

"file.txt"

,

"w"

)

;

   

fprintf

(

fp

,

"%s"

,

"This is runoob.com"

)

;

   

fclose

(

fp

)

;

   

   

return

(

0

)

;

}

Let us compile and run the program above, which will create a file file.txt, then write the following lines of text, and finally use the fclose() function to close the file.



这里是 runoob.com

C Standard Library - <stdio.h> C Standard Library -