[ First ] [ Previous ] [ Next ] [ Last ] [ Manuals ]
freopen

Re-direct a stream to another file.
Compatibility:
This function is compatible with the following targets:
Prototype:
#include <stdio.h>
FILE *freopen(const char *filename,
   const char *mode, FILE *stream);
Parameters:
Parameters for this facility are:
Remarks:
The freopen() function changes the file stream is associated with to another file. The function first closes the file the stream is associated with, and opens the new file, filename, with the specified mode, using the same stream.
Return:
fopen() returns the value of stream, if it is successful. If fopen() fails it returns a null pointer (NULL).
See Also:
"fopen"
Example of freopen() usage:
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
FILE *f;
// re-direct output from the console to a new file
if (( f = freopen("newstdout", "w+", stdout)) == NULL) {
printf("Can't create new stdout file.\n");
exit(1);
}
printf("If all goes well, this text should be in\n");
printf("a text file, not on the screen via stdout.\n");
fclose(f);
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