liveBook · Manning

Fclose

As explained in Modern C

fclose is the C standard library function that closes a stream and flushes its buffered output.

fclose closes a C stream and flushes its buffered output to its destination. Closing is therefore more than ending access: it ensures pending output is delivered. section 8.3.3

Keep these practical distinctions in view:

  • Use fclose when the stream is no longer needed and should be closed after its buffered output has been flushed. section 8.3.2 section 8.3.3
  • Use fflush when output must reach its destination immediately but the stream must remain open. section 8.3.3
  • Remember that text output is commonly buffered, so visible terminal output may depend on line buffering or an explicit flush. section 8.3.3

Flushing buffered output

A delayed-output demonstration writes dots to stdout and conditionally calls fflush(stdout). That makes the difference clear: fflush exposes output while the stream remains active; fclose provides the final flush when the stream is closed. section 8.3.3

How Modern C covers it

How deep it goes
Defines the interface and buffering consequence, but stops short of detailed error handling or stream-lifecycle edge cases.
Examples
Demonstrates buffered stdout with delayed dots and contrasts explicit fflush with eventual closing.
What it assumes
Assumes familiarity with FILE streams and introduces buffering through visible terminal-output behavior.
What you can do after
Operate C streams by choosing fclose for completion and fflush for interim delivery.
How it connects
Links streams, FILE pointers, fflush, fopen, and freopen through C stream management.

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.