File Handling in C
File handling allows you to store and access data permanently on disk. Unlike variables (which lose their values when the program ends), a file retains its contents even after the program closes.Steps in File Handling
- Declare a file pointer
- Open the file
- Perform read/write operations
- Close the file
File Opening Modes
Common File Functions
Writing to a File
Reading from a File
Appending to a File
Checking for NULL
Always check iffopen() returned NULL — it means the file could not be opened (wrong path, no permissions, etc.):