Skip to content

Latest commit

 

History

History
40 lines (24 loc) · 3.11 KB

stream-states.md

File metadata and controls

40 lines (24 loc) · 3.11 KB
description title ms.date helpviewer_keywords ms.assetid
Learn more about: Stream States
Stream States
11/19/2018
streams, states
5f28c968-f132-403f-968c-8417ff315e52

Stream states

The valid states, and state transitions, for a stream are shown in the following figure.

Stream state diagram.

Each of the circles denotes a stable state. Each of the lines denotes a transition that can occur as the result of a function call that operates on the stream. Five groups of functions can cause state transitions.

Functions in the first three groups are declared in <stdio.h>:

Functions in the remaining two groups are declared in <wchar.h>:

The state diagram shows that you must call one of the position functions between most write and read operations:

  • You can't call a read function if the last operation on the stream was a write.

  • You can't call a write function if the last operation on the stream was a read, unless that read operation set the end-of-file indicator.

Finally, the state diagram shows that a position operation never decreases the number of valid function calls that can follow.

See also

Files and streams