Latest web development tutorials

C library functions - fclose ()

C standard library - <stdio.h> C standard library - <stdio.h>

description

C library functionint fclose (FILE * stream) to close the flow stream.Flush all buffers.

statement

Here is the fclose () function's declaration.

int fclose(FILE *stream)

parameter

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

return value

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

Examples

The following example demonstrates the fclose () function is used.

#include <stdio.h>

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

   fprintf(fp, "%s", "这里是 w3cschool.cc");
   fclose(fp);
   
   return(0);
}

Let's compile and run the above program, which will create a filefile.txt, then write the following lines of text, and then use fclose ()function closes the file.

这里是 w3cschool.cc

C standard library - <stdio.h> C standard library - <stdio.h>