5.5. Opening a Stream[View full width]#include <stdio.h> FILE *fopen(const char *restrict pathname , const ![]() FILE *freopen(const char *restrict pathname , const ![]() FILE *restrict fp ); FILE *fdopen(int filedes , const char *type ); |
All three return: file pointer if OK, NULL on error |
- Output cannot be directly followed by input without an intervening fflush, fseek, fsetpos,or rewind.
- Input cannot be directly followed by output without an intervening fseek, fsetpos,or rewind, or an input operation that encounters an end of file.
We can summarize the six ways to open a stream from Chapter 3.By default, the stream that is opened is fully buffered, unless it refers to a terminal device, in which case it is line buffered. Once the stream is opened, but before we do any other operation on the stream, we can change the buffering if we want to, with the setbuf or setvbuf functions from the previous section.An open stream is closed by calling fclose.
#include <stdio.h> int fclose(FILE *fp ); |
Returns: 0 if OK, EOF on error |
![](/image/library/english/13775_pixel.gif)