In C, a file refers to a disk file, a terminal, a printer, or a tape drive. In other words, a file represents a concrete device
with which you want to exchange information. A stream, on the other hand, is a series of bytes through which you
read or write data to a file. Unlike a file, a stream is device-independent. All streams have the same behavior.
In addition, there are three file streams that are pre-opened for you:
- stdin—The standard input for reading.
- stdout—The standard output for writing.
- stderr—The standard error for writing error message.
Usually, the standard input stdin links to the keyboard, while the standard output stdout and the standard error stderr
point to the screen. Also, many operating systems allow you to redirect these file streams.
By default, all I/O streams are buffered. The buffered I/O is also called the high-level I/O.
The FILE structure is the file control structure defined in the header file stdio.h. A pointer of type FILE is called a file
pointer and references a disk file. A file pointer is used by a stream to conduct the operation of the I/O functions. For
instance, the following defines a file pointer called fptr:
FILE *fptr;
In the FILE structure, there is a member, called the file position indicator, that points to the position in a file where
data will be read from or written to.
The C language provides a set of rich library functions to perform I/O operations. Those functions can read or write
any types of data to files. Among them, fopen(), fclose(), fgetc(), fputc(), fgets(), fputs(), fread(), fwrite(), feof(),
fscanf(), fprintf(), fseek(), ftell(), rewind(), and freopen() have been introduced

No comments:
Post a Comment