


You are only allowed to read or write from the current file position. If your stream is actually a pipe or a socket, or is opened in mode append then you are not allowed to fseek(). If you open your stream only for write then calling fread() will cause an error. If you open your stream only for read then calling fwrite() will cause an error. Now here's where it gets "icky." At the time a stream is opened a variety of factors determine which of the above operations are enabled or disabled. The current position can also be changed with fseek() and queried with ftell(). There are some basic operations ( fread() and fwrite()) that read or write an arbitrary number of bytes starting at the current position, and then reset the current position to point just after the most recently read or written byte. My best cut at it is that it is an abstraction representing a buffered file (where "file" is understood in the Unix sense of the word as something that is usually (but not always) a sequence of bytes and a current file position.)Īt it's most general a stream is like a sequence of bytes numbered from 0, that can be arbitrarily extended at the end, but that has some additional state (the current position). A queue is an abstract data type with two operations: enqueue() and dequeue() (or sometimes push() and pop()) that have first-in-first-out semantics.Ī C stream is hard (for me) to describe abstractly.
