The function fclose () in C

Int fclose function (FILE * stream) in Library C closes Stream. All buffers are flushed (erased or moved to the periphery).

Int fclose function (FILE * stream) in Library C closes Stream. All buffers are flushed (erased or moved to the periphery).

Declare the function fclose () in C

Here is the declaration for fclose () function in C:

 int fclose ( FILE * stream ) 

Parameters

stream - This is the pointer to the FILE object that identifies Stream to be closed.

Returns the value

This method returns 0 if Stream is successfully closed. If failure, EOF is returned.

For example

The following program C illustrates the usage of the fclose () function in C:

 #include int main () { FILE * fp ; fp = fopen ( "baitapc.txt" , "w" ); fprintf ( fp , "%s" , "Hoc C co ban va nang cao tai QTM !!!" ); fclose ( fp ); return ( 0 ); } 

Compiling and running the above C program will create a bait.txt file , and then it will write the following text line and eventually it will close this file using the fclose () function. And see the results.

According to Tutorialspoint

Last lesson: stdio.h in C

Next lesson: Function clearerr () in C

5 ★ | 1 Vote