Pages

Thursday, 20 October 2016

fclose : C Language stdio.h

fclose

 Closes a stream

 Declaration:  int fclose(FILE *stream);

 Remarks:

fclose closes the named stream.

All buffers associated with the stream are flushed before closing.

System-allocated buffers are freed upon closing.

Buffers assigned with setbuf or setvbuf are not automatically freed. (But if
setvbuf is passed null for the buffer pointer, it will free it upon close.)

 Return Value
  þ On success, returns 0
  þ On error, returns EOF

 Portability:

DOS
Yes
UNIX
Yes
C++ Only



 Example:


 #include <string.h>
 #include <stdio.h>

 int main(void)
 {
    FILE *fp;
    char buf[11] = "0123456789";

    /* create a file containing 10 bytes */
    fp = fopen("DUMMY.FIL", "w");
    fwrite(&buf, strlen(buf), 1, fp);

    /* close the file */
    fclose(fp);
    return 0;
 }

Download PDF


No comments:

Post a Comment