[prev] 48 [next]

Buffered I/O (cont)

The standard i/o library (stdio.h) provides buffered i/o
  • from tty-like devices, generally line buffered
  • from disk-like devices (files), read/written in BUFSIZ chunks
    • via OS buffers, so may not need disk access each time
  • buffering hidden from user, who sees getchar(), fgets(), etc.
  • buffer is allocated by fopen(), removed by fclose()
The FILE object (normally manipulated via a FILE * pointer)
  • contains the buffer, malloc'd on fopen()
  • contains current position within the buffer and file
  • etc. etc.