The valid states, and state transitions, for a stream are:
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>
:
fgetc
, fgets
, fread
, fscanf
, getc
, getchar
, gets
, scanf
, and ungetc
fprintf
, fputc
, fputs
, fwrite
, printf
, putc
, putchar
, puts
, vfprintf
,
and vprintf
fflush
, fseek
, fsetpos
, and rewind
Functions in the remaining two groups are declared in <wchar.h>
:
fgetwc
, fgetws
, fwscanf
, getwc
, getwchar
, ungetwc
, and wscanf
, fwprintf
, fputwc
, fputws
, putwc
, putwchar
, vfwprintf
, vwprintf
, and
wprintf
For the stream s
, the call fwide
(s, 0)
is always valid and never causes a change of state. Any other call to fwide
,
or to any of the five groups of functions described above, causes the state transition shown in the state diagram. If no
such transition is shown, the function call is invalid.
The state diagram shows how to establish the orientation of a stream:
fwide
(s, -1)
, or to a byte read or byte write function, establishes the stream as byte-oriented. fwide
(s, 1)
, or to a wide read or wide write function, establishes the stream as wide-oriented. The state diagram also shows that you must call one of the position functions between most write and read operations:
Finally, the state diagram shows that a position operation never decreases the number of valid function calls that can follow.