fclose(3C)
_________________________________________________________________
fclose function
Close a specified file.
_________________________________________________________________
Calling Sequence
#include <stdio.h>
FILE *fp;
int fclose();
fclose(fp);
where fp is a pointer to an I/O packet.
Description
The fclose function flushes the specified file's buffer, and then
closes the file.
The include file stdio.h defines this function.
Returns
The function returns -1 on an error, and 0 otherwise.
Related Functions
See also the exit and fflush functions.
Example
/* Program test for the fclose() function */
#include <stdio.h>
FILE *fopen(), *fp;
int i = 1, fclose();
main(argc, argv)
int argc;
char *argv[];
{
while (i < argc) {
fp = fopen(argv[i], "r");
printf("%c\n", fgetc(fp));
DG/UX 4.00 Page 1
Licensed material--property of copyright holder(s)
fclose(3C)
(void) fclose(fp);
i++;
}
}
If you call program test with files a, b, c, and d where the
files contain, respectively, aaaaaaa, bbbbbbb, ccccccc, and
ddddddd, you generate the output
a
b
c
d
The program opens each file in turn, gets the first character,
and closes the file.
DG/UX 4.00 Page 2
Licensed material--property of copyright holder(s)