liveBook · Manning

Streaming

As explained in Modern C

Streaming is the incremental handling of a sequence of data items, including their processing, transfer, or consumption as they become available.

A C stream provides an interface for output without exposing its implementation. The standard output streams are stdout for usual output and stderr for urgent output; file streams extend the same approach to permanent storage. section 8.3.1 section 8.3.2

Use the stream-oriented functions to direct unformatted output:

  • Call fputc to write one character or fputs to write a string; both take a stream argument. section 8.3.1
  • Open a file with fopen and a mode such as "a" for appending. Check for failure, and use perror to report it. section 8.3.2
  • Treat FILE as opaque: rely on its functional interface rather than implementation details. section 8.3.1

Append a log message

Open "mylog.txt" in append mode, check the returned stream, then write a line with fputs. A separate example redirects stdout to a file with freopen, allowing puts to write there. section 8.3.2

int fputc(int c, FILE* stream);
int fputs(char const s[static 1], FILE* stream);


!@%STYLE%@!
{"css":"{\"css\": \"font-weight: bold;\"}","target":"[[{\"line\":0,\"ch\":0},{\"line\":0,\"ch\":3}],[{\"line\":1,\"ch\":0},{\"line\":1,\"ch\":3}],[{\"line\":0,\"ch\":4},{\"line\":0,\"ch\":9}],[{\"line\":0,\"ch\":0},{\"line\":0,\"ch\":3}],[{\"line\":1,\"ch\":0},{\"line\":1,\"ch\":3}],[{\"line\":0,\"ch\":17},{\"line\":0,\"ch\":21}],[{\"line\":1,\"ch\":34},{\"line\":1,\"ch\":38}],[{\"line\":0,\"ch\":0},{\"line\":0,\"ch\":3}],[{\"line\":1,\"ch\":0},{\"line\":1,\"ch\":3}],[{\"line\":1,\"ch\":4},{\"line\":1,\"ch\":9}],[{\"line\":1,\"ch\":10},{\"line\":1,\"ch\":20}],[{\"line\":1,\"ch\":23},{\"line\":1,\"ch\":29}],[{\"line\":0,\"ch\":17},{\"line\":0,\"ch\":21}],[{\"line\":1,\"ch\":34},{\"line\":1,\"ch\":38}]]"}
!@%STYLE%@!

The function signatures show how fputc and fputs receive a stream as an argument. section 8.3.1

How Modern C covers it

How deep it goes
Explains output interfaces, file modes, and error checks while deferring FILE implementation details.
Examples
Demonstrates a manual puts implementation, appending a log line, and redirecting stdout to a file.
What it assumes
Recognizes FILE* as a pointer and learns stream validity checks while pointer details remain deferred.
What you can do after
Apply C stdio functions to write output to standard streams or an opened file.
How it connects
Connects FILE streams with fputc, fputs, fopen, freopen, stdout, and stderr.

Also explained in

Compare how 19 books explain streaming →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Modern C. The section links point to the parts of the book it draws on.