C Programming Language

fclose()

Declaration: int fclose (FILE *stream);

                       The fclose function closes the file associated with stream and flushes its buffer (i.e., it writes any data still remaining in the disk buffer to the file). After a call to fclose(), stream is no longer connected with the file, and any automatically allocated buffers are de allocated.

                        If fclose () is successful, zero is returned; otherwise EOF is returned.

For example, the following code opens and close a file:

#include<stdio.h>
#include<stdlib.h>
int main()
      {
      FILE *fptr;
      If((fptr = fopen(“TEST”,”w”))==NULL)
                {
                 printf(“Cannot open file\n”);
                 exit(1);
                 }
      if(fclose(fptr))
                  pritf(“File close error\n”);
       return o;
       }

fopen() Home fputc()

c program stats