What is a file
A file is essentially a serial sequence of bytes stored on your hard drive.
A file has a beginning and an end. File current position is typically defined as so many bytes from the beginning.
The current position is where any file action (read and write) will take place. You can move the current position to any other point in the file.
The C library provides functions for reading and writing to or from data streams.
- A stream is an abstract of data source.
- The keyboard, the command line on your display,
- and files on disk are all examples of streams.
You therefore use the same input/output functions for reading and writing any external device that is mapped to a stream.
Text file stores data as a characters organized as lines, where each line is terminated by a newline character.
Binary file stores data as a series of bytes, exactly as it appears in memory, so a value of type double for example would be written as the 8 bytes that appear in memory.