Skip to main content

Text file versus binary file

Short answer

Text files store data as readable ASCII characters; they are larger, use functions like fprintf/fscanf, and open with modes "r" or "w". Binary files store data as raw bytes in memory representation; they are smaller, use fread/fwrite, and modes "rb" or "wb".

Differentiate between text file and binary file.

BasisText fileBinary file
StorageData as readable characters (ASCII)Data in the same form as in memory (raw bytes)
ReadableCan be opened in an editorNot readable in an editor
SizeLarger (a number like 12345 uses 5 bytes)Smaller (an int always uses 4 bytes)
Functionsfprintf, fscanf, fgets, fputsfwrite, fread
NewlineTranslated on some systems (e.g. Windows)No translation
SpeedSlower (conversion needed)Faster (no conversion)
Mode"r", "w""rb", "wb"

✓ Answer checked by Claude Opus 5.5 (high effort)

All Computer Programming chapter 10 questions →