[ First ] [ Previous ] [ Next ] [ Last ] [ Manuals ]
fclose

Close an open file.
Compatibility:
This function is compatible with the following targets:
Prototype:
#include <stdio.h>
int fclose(FILE *stream);
Parameters:
Parameters for this facility are:
Remarks:
The fclose() function closes a file created by fopen(), freopen(), or tmpfile(). The function flushes any buffered data to its file and closes the stream. After calling fclose(), stream is no longer valid and cannot be used with file functions unless it is reassigned using fopen(), freopen(), or tmpfile().
All of a program's open streams are flushed and closed when a program terminates normally.
fclose() closes then deletes a file created by tmpfile().
NOTE
On embedded/ RTOS systems this function only is implemented for stdin, stdout and stderr files.
Return:
fclose() returns a zero if it is successful and returns a -1 if it fails to close a file.
See Also:
"fopen"
"freopen"
"tmpfile"
"abort"
"exit"
Example of fclose() usage.:
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
FILE *f;
static char name[] = "myfoo";
// create a new file for output
if ( (f = fopen(name, "w")) == NULL) {
printf("Can't open %s.\n", name);
exit(1);
}
// output text to the file
fprintf(f, "pizza sushi falafel\n");
fprintf(f, "escargot sprocket\n");
// close the file
if (fclose(f) == -1) {
printf("Can't close %s.\n", name);
exit(1);
}
return 0;
}
[ First ] [ Previous ] [ Next ] [ Last ] [ Manuals ]
Visit the Metrowerks website at: http://www.metrowerks.com
For assistance contact Metrowerks Technical Support at: cw_support@metrowerks.com
Copyright © 2000, Metrowerks Corp. All rights reserved.
Last updated: August 16, 2000