- 2072 Chaitra · 1+3 marks
Data file and file modes
Short answer
A data file is a permanently stored named collection of data on disk. File modes given to fopen() include "r" (read existing), "w" (write, create/erase), "a" (append), "r+" (read/write existing), "w+" (read/write, create/erase), "a+" (read/append). Add "b" for binary, e.g., "rb", "wb".
What is a data file in C? What are the modes in file handling? Explain briefly.
Data file
A data file is a named collection of data stored permanently on a disk. Programs read data from it and write results to it, so the data stays after the program ends and large data need not be typed again. Files are of two kinds: text files and binary files.
File modes
The mode is given as the second argument of fopen().
| Mode | Meaning |
|---|---|
r | Open existing file for reading; fails if it does not exist |
w | Open for writing; creates the file, or erases the old contents |
a | Open for appending; writes go at the end, file is created if absent |
r+ | Read and write on an existing file |
w+ | Read and write; creates new / erases old |
a+ | Read and append |
For binary files b is added: rb, wb, ab, rb+, wb+, ab+.
✓ Answer checked by Claude Opus 5.5 (high effort)
Related questions
- Opening and closing a data file · Computer Programming, chapter 10 · asked 2×
- Copy contents of one file to another · Computer Programming, chapter 10 · asked 2×
- Store 48 students in file with append · Computer Programming, chapter 10
- Employee text file; sort into binary file · Computer Programming, chapter 10
- INVENTORY file of items · Computer Programming, chapter 10
- Display records sorted by name from file · Computer Programming, chapter 10
- File system handling of kernel · Embedded System, chapter 6
- Handling voluminous data · Information System, chapter 8
- Instruction and data format, addressing modes · Microprocessor, chapter 2 · asked 2×
- Modes of parallel data transfer · Microprocessor, chapter 4