File handling allows programs to read from and write to files on disk.
This is useful for saving data, logs, and configurations.
A file is handled using a FILE pointer.
Use fopen() to open a file.
It returns a pointer to the file.
Common file modes include:
"r" – read"w" – write (overwrite)"a" – appendAlways close files after use to free resources.
Use fprintf() to write formatted data to a file.
Use fscanf() or fgets() to read data.
You can read one character at a time using fgetc().
Always check if the file opened successfully.
Use append mode to add data without overwriting existing content.
Writing and reading from a file in one program.
File handling is used in many real-world applications.
Be careful with these:
Write a program that writes text to a file and then reads and prints it.