Question Details

No question body available.

Tags

c io posix

Answers (1)

June 27, 2026 Score: 6 Rep: 159,599 Quality: Medium Completeness: 50%

3 thoughts:

Push back:

C allows ungetc() of at least 1 character so fgetc() needs to check for the push-back character each time it is called. fread() may only need to do this for the first character, thus simplifies the reading of subsequent characters.

Parameter checking, set up and I/O access locking

Each function incurs some O(1) overhead per call. Thus n calls to fgetc()/fputc() incur n times this overhead, fread()/fwrite() incurs 1 times this overhead, even when n is large.

Error checking:

Somewhat like the above. Each completed I/O function may generate an I/O error or end-of-file (on reads). This is done n times when calling single character functions, yet usual is done once on fread(n)/fwrite(n).