- 2069 Chaitra · 2 marks
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.
| Basis | Text file | Binary file |
|---|---|---|
| Storage | Data as readable characters (ASCII) | Data in the same form as in memory (raw bytes) |
| Readable | Can be opened in an editor | Not readable in an editor |
| Size | Larger (a number like 12345 uses 5 bytes) | Smaller (an int always uses 4 bytes) |
| Functions | fprintf, fscanf, fgets, fputs | fwrite, fread |
| Newline | Translated on some systems (e.g. Windows) | No translation |
| Speed | Slower (conversion needed) | Faster (no conversion) |
| Mode | "r", "w" | "rb", "wb" |
✓ Answer checked by Claude Opus 5.5 (high effort)
Related questions
- Employee text file; sort into binary file · Computer Programming, chapter 10
- Binary file of 48 students; highest mark · Computer Programming, chapter 10
- File stream; student binary file program · Object Oriented Programming, chapter 8
- Audio quality versus file size · Multimedia System, chapter 2